This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-05-31
Channels
- # aws (2)
- # beginners (101)
- # cider (8)
- # clara (8)
- # cljs-dev (3)
- # cljsrn (17)
- # clojars (2)
- # clojure (67)
- # clojure-austin (2)
- # clojure-finland (1)
- # clojure-france (5)
- # clojure-italy (3)
- # clojure-nl (3)
- # clojure-russia (2)
- # clojure-serbia (1)
- # clojure-spec (72)
- # clojure-uk (112)
- # clojurescript (92)
- # core-async (74)
- # core-typed (2)
- # cursive (8)
- # datomic (2)
- # duct (5)
- # emacs (35)
- # events (11)
- # fulcro (32)
- # instaparse (9)
- # jobs (1)
- # luminus (1)
- # lumo (3)
- # off-topic (118)
- # om (2)
- # onyx (10)
- # pedestal (5)
- # re-frame (21)
- # reagent (48)
- # reitit (40)
- # ring (12)
- # shadow-cljs (113)
- # spacemacs (21)
- # tools-deps (47)
FYI, we’ve just merged :resolve-aliases
support in to lein-tools-deps
. Currently available only on the 0.4.x branch:
https://github.com/RickMoynihan/lein-tools-deps/blob/0.4.x/example/project.clj#L20
How do I load a Clojure file on the classpath from the CLI? I tried doing clj -i my.ns
and I get a FileNotFound exception.
Say I have a monolith type git repo that looks something like this:
mylib1
mylib2
mylib2
has a deps.edn
files that looks like this:
{:deps {mylib1 {:local/root "../mylib1"}}}
Is it possible to use mylib2
as a git dep (`{:git/url "https://github.com/..." :sha "..." :deps/root "mylib2"}`) from the CLI and have mylib1
dependency be resolved using the :local/root
path and the same :sha
used previously?Or perhaps even changing mylib1
coordinate to be {:git/url "
and the :sha
would be automatically set to the same :sha
used for the the git URL
that is already on the classpath.
In short, no - git libs are only resolved from git
If I have foo.clj:
(ns foo)
(defn bar
[& args]
(prn *command-line-args*))
And run:
clj -i foo.clj -e '(foo/bar)' asd
I get a FileNotFoundException.I assume this is because it is expecting the last param to be a path. Why does it require that?
@kenny https://github.com/clojure/clojure/blob/master/src/clj/clojure/main.clj#L388-L417 hope that helps
Are relative paths wonky for deps? For instance, if you local/root a deps.end which in turn local/root’s a dep (something like “../../../whatever”) is the “../../..” going to mess things up if the top level isn’t in a “../../../” relationship to that project?
@kenny Use -
to introduce the arguments: clj -i foo.clj -e '(foo/bar)' - asd
@seancorfield The program doesn't exit then.
Ah, yes, you'd have to send it empty input 🙂
You can only get *command-line-args*
if you have main-opts
Rename bar
to -main
and then clj -i foo.clj -m foo asd
(! 633)-> cat foo.clj
(ns foo)
(defn -main
[& args]
(prn *command-line-args*))
Thu May 31 13:08:39
(sean)-(jobs:0)-(~/clojure/kenny)
(! 634)-> clj -i foo.clj -m foo asd
("asd")
Add another namespace for this entry point?
Perhaps. But I may have 50 different functions that I'd like to call. I don't want 50 namespaces to simply call a function.
OK, how about this:
(! 638)-> cat foo.clj
(ns foo)
(defn -main [& args] (println "I am foo's -main"))
(ns foo.main)
(defn -main
[& args]
(prn *command-line-args*))
Thu May 31 13:10:56
(sean)-(jobs:0)-(~/clojure/kenny)
(! 639)-> clj -i foo.clj -m foo
I am foo's -main
Thu May 31 13:11:04
(sean)-(jobs:0)-(~/clojure/kenny)
(! 640)-> clj -i foo.clj -m foo.main asd
("asd")
(multiple namespaces in one file 🙂 )
Still feels like a bit of a hack but that could work. It seems like it'd be useful to have a CLI option to execute a function besides -main
.
We have a job
script at work whose first argument is a namespace-qualified symbol and it calls that from -main
. So you'd say clj -i job.clj -m job job/foo asd
Relying on dynamic require
and resolve
It doesn't seem to work. Example a/deps.edn
:
{:deps {org.clojure/tools.cli {:mvn/version "0.3.7"}}}
b/deps.edn
:
{:deps {a {:git/url ""
:sha "7b8e5c33588a94c1318e225dc9fe655599216370"}}
:aliases {:dev {:override-deps {a {:local/root "../a"}}}}}
Result of clj -A:dev -Sforce -Spath
:
src:/home/kenny/.m2/repository/org/clojure/clojure/1.9.0/clojure-1.9.0.jar:/home/kenny/.gitlibs/libs/a/a/7b8e5c33588a94c1318e225dc9fe655599216370/src/main/clojure:/home/kenny/.m2/repository/org/clojure/spec.alpha/0.1.143/spec.alpha-0.1.143.jar:/home/kenny/.m2/repository/org/clojure/core.specs.alpha/0.1.24/core.specs.alpha-0.1.24.jar
That classpath does not contain tools.cli as required by the overridden a
dependency.No, there is a ticket for this right now
https://dev.clojure.org/jira/browse/TDEPS-51. Is the plan to allow this behavior or throw?