Fork me on GitHub
#tools-deps
<
2022-08-12
>
grzm13:08:48

Is there a way to reference an alias that includes a :main-opts but does not actually call the -main when referenced? Similar to how you can use -X with an alias that includes an exec-fn but include it with -A and it won't call the function. Example in thread 🧵

grzm13:08:25

% cat deps.edn 
{:aliases
 {:main {:extra-paths ["src"]
         :main-opts ["-m" "com.grzm.ex.main"]
         :exec-fn com.grzm.ex.main/exec}
  :exec {:extra-paths ["src"]
         :exec-fn com.grzm.ex.main/exec}}}

% cat src/com/grzm/ex/main.clj 
(ns com.grzm.ex.main)

(defn exec [_]
  (println "Hello, exec!"))

(defn -main [& _args]
  (println "Hello, main!"))

% clj -X:exec
Hello, exec!
Called exec-fn
% clj -A:exec
Clojure 1.10.3
user=> 
Opened a repl with the appropriate classpath. Didn’t call exec-fn.
% clj -M:main
Hello, main!
Called -main.
% clj -A:main
WARNING: Use of :main-opts with -A is deprecated. Use -M instead.
Hello, main!
I’d like this last to open a repl, rather than call the -main Is there an alternative incantation that would do this that I’m missing?

Alex Miller (Clojure team)13:08:20

No, separate into two aliases

grzm13:08:05

Cool. Thanks, @U064X3EF3!

grzm13:08:47

(And thanks for calc-trace 🙂)