Fork me on GitHub
#tools-deps
<
2022-08-02
>
thheller08:08:47

is there something in tools deps nowadays that can run a CLJ function from the command line, without it doing any argument parsing itself? -X presumes the only argument is a EDN map and parses it as such. -M -m only runs -main? I want clj -? some.ns/some-fn foo?

thheller08:08:57

just remembered I opened a ticket for that for clojure.main itself which would work I guess https://clojure.atlassian.net/browse/CLJ-2316

borkdude10:08:31

My opinion: introducing a new -f flag seems too much overkill to me for such a simple tweak (and babashka uses -f to indicate --file...), but I think it would be good to have this. lein and bb do support -m foo/bar @thheller What about doing this in user space (for now)?

(ns run-main)

(let [[main-fn & args] *command-line-args*]
  (apply (requiring-resolve (symbol main-fn)) args))
$ clj -M /tmp/run_main.clj clojure.core/prn 1 2 3
"1" "2" "3"

borkdude10:08:24

When moving this to its own -main function, you could hide this behind an alias, so you can do:

clj -M:run clojure.core/prn 1 2 3

thheller10:08:04

just checking if there is something built-in nowadays that I maybe missed

thheller10:08:10

I'd prefer if -m just did this by default, similar to how lein run -m foo/bar or lein run -m foo does (ie. accepting both)

👍 1