Fork me on GitHub
#tools-deps
<
2022-11-15
>
baptiste-from-paris18:11:54

Hello all, I have a question on deps Tools, the -T option. I’ve noticed that args need a key/value pair which does not satisfy my use case. For example clj -Tcljd -main 1 2 3 will generate a Key is missing value: 3 error. Is there a way around this ?

seancorfield18:11:37

-T works like -X and calls a function with a hash map. You can't call -main as that expects a sequence of strings.

seancorfield18:11:29

You would need an "exec" function entrypoint such as:

(defn main-x [{:keys [args]}] (apply -main args))
which you could then invoke as
clojure -Tcljd main-x :args '["1" "2" "3"]'
(you could do (apply -main (map str args)) and then pass :args '[1 2 3]' on the command-line if you wanted to avoid the quoting).

seancorfield18:11:21

But the usual approach is to have -main parse its arguments into a hash map and then call an "exec" style function -- parsing string args with something like clojure.tools.cli (which produces a hash map of arguments).

seancorfield18:11:28

The Cognitect test-runner is structured like that: https://github.com/cognitect-labs/test-runner It has an api.clj entrypoint for direct exec that massages the initial hash map something before invoking the same function that -main invokes.

baptiste-from-paris18:11:43

Ok, thanks a lot Sean 🙏