Fork me on GitHub
#tools-deps
<
2020-11-01
>
Jakub Holý (HolyJak)17:11:31

Hello! I am sorry, I obviously am not good enough in reading docs. What do I need to do to be able to run my project with just clj -X without arguments? I have tried

{:deps {...}
 :exec-fn   clj-tumblr-summarizer.main/-main}
but that complains "No function found on command line or in :exec-fn" (https://clojure.org/guides/deps_and_cli#_using_a_main does not mention how to hardcode the function. I have also tried https://clojure.org/reference/deps_and_cli#_running_a_main_or_script and add :main-opts ["-m" "clj-tumblr-summarizer.main/-main"])

3
practicalli-john18:11:58

You need to define an alias to use with the -X flag. My understanding is the -X flag should be used with an alias, as I havent seen any examples of using :exec-fn as a top level key. From the error you are getting, this seems to be a correct... There are plenty of examples of :exec-fn , :exec-args and :ns-default in the practicalli/clojure-deps-edn https://github.com/practicalli/clojure-deps-edn

vlaaad18:11:08

I think exec-fn has to be in alias, and -X requires alias

practicalli-john18:11:27

You can specify :exec-fn on the command line I believe, if you really dont want an alias Edit: hmm, I am not sure that is right now. You can specify a function, but still has to be with an alias. Edit: as borkdues says below, if its a fully qualified function on the class path, then the command line is enough - need to add some good examples to the book so I dont forget

borkdude19:11:52

That's not true though:

$ clj -X clojure.core/prn :foo 1 :bar 2
{:foo 1, :bar 2}

👍 3
seancorfield19:11:05

You can't run just clj -X on its own. You either have to provide an alias or you have to specify the function to call on the command-line.

👍 3
seancorfield19:11:50

Just like :main-opts can't be at the top level in deps.edn, :exec-fn, :exec-args, :ns-default, etc all need to be under an alias.

seancorfield19:11:34

There are only a few keys valid at the top level @U0522TWDA

:deps - map of lib (symbol) to coordinate
:paths - vector of paths
:aliases - map of alias name to alias data
provider-specific keys for configuring dependency sources
(that last one is stuff like :mvn/repos)