lein run: --quote-args flag has no effect?
metametadata opened this issue · comments
I want to use lein run
with the function which has non-string args. --quote-args
seems to be the solution for it but it doesn't work. From lein run --help
:
The `--quote-args' flag quotes the arguments passed in, instead of converting
them to strings. Useful if you want to pass in :project/key entries that might
be/contain lists.
I may misunderstand the purpose of the flag though. Unfortunately, I couldn't find any usage examples in tests or on the Internet.
To Reproduce
- Code:
(ns foo.core) (defn bar [x y z] (prn x (type x) y (type y) z (type z)))
- Run the command
lein trampoline run -m foo.core/bar --quote-args 123 :a "b"
. - See output.
Actual behavior
"123" java.lang.String ":a" java.lang.String "b" java.lang.String
Expected behavior
123 java.lang.Long :a clojure.lang.Keyword "b" java.lang.String
Environment
- Leiningen Version: Leiningen 2.9.6.
- Leiningen installation method: Homebrew.
- JDK Version: openjdk version "11.0.8".
- OS: macOS 11.5.2.
One workaround is to use clojure.main
:
$ lein trampoline run -m clojure.main -e "(require 'foo.core)(foo.core/bar 123 :a \"b\")"
...
123 java.lang.Long :a clojure.lang.Keyword "b" java.lang.String
I think this is just a case of misleading documentation. Arguments passed in from the CLI will always be strings; they can't be any other way. But the run
task can take arguments from other places, like when you create an :aliases
entry which invokes it. In that case, you can put non-string data in, and --quote-args
should protect it.
For example: :aliases {"wat" ["run" "--quote-args" "-m" "hey.core/foo" {:abc 123}]}
Improved the docs in 4b43164.
Got it, thanks!