Closed chr15m closed 4 years ago
Command line args are available in *ARGV*
or in *command-line-args*
:
$ bootleg -d -e '*command-line-args*'
("-d" "-e" "*command-line-args*")
$ bootleg -d -e '*ARGV*'
("-d" "-e" "*ARGV*")
The clojure System
namespace is now available (java.lang.System https://docs.oracle.com/javase/8/docs/api/java/lang/System.html ) and this includes getenv
:
$ FOO=bar bootleg -d -e '(System/getenv "FOO")'
"bar"
And I have included the clojure.tools.cli
namespace that you can require
as needed to process command line args, or reference directly:
$ bootleg -d -e '(clojure.tools.cli/parse-opts *command-line-args* [["-e" "--evaluate CODE" ""] ["-d" "--data" ""]])'
{:options {:data true,
:evaluate "(clojure.tools.cli/parse-opts *command-line-args* [[\"-e\" \"--evaluate CODE\" \"\"] [\"-d\" \"--data\" \"\"]])"},
:arguments [],
:summary " -e, --evaluate CODE\n -d, --data",
:errors nil}
If you want to pass in edn in a env var or command line you can use edamame's reader that is already available under parse-string
:
$ FOO='{:a 1 :b 2}' bootleg -d -e '(-> "FOO" System/getenv parse-string :b)'
2
Awesome, will test. Thank you.
Removed *ARGV*
. Although other lisps have this dynamic var it would be best to just have one way that matches clojure's.
Alternatively / additionally a way to pass flags in. Maybe a
-f someflag=12
or even allowing command line eval as well as file input.Basically I want a way to call my script and set a conditional from outside.