Using tools.cli, how can I can I create a non-optional argument with optional ones?
I have a function
(defn parse-opts
[args]
(cli args
["-f" "--ifn" "input file"]
(optional ["-o" "--outp" ".csv pipe delimited output file"
:default "assess_pro_out.csv"] identity)
(optional ["-d" "--debug" "Debug flag for logging." :default 0
:parse-fn #(Integer. %)])))
that compiles but produces
Exception in thread "main" clojure.lang.ArityException:
Wrong number of args (2) passed to: PersistentVector
when I run my main program without arguments.
If this option is made like the rest
(optional ["-f" "--ifn" "input file"] identity)
everything works fine.
I just want one parameter to be non-optional. What am I doing wrong?
I do have a workaround for this, but I’d still like to know if it is okay to mix optional and non-optional arguments to cli.
(defn -main
[& args]
(let [opts (parse-opts args)
start-time (str (Date.))
parsed-csv-data (if-not (:ifn opts)
(do
(println "Usage: assess-chk [-f -ifn] input-file-name")
(System/exit -2))
(utl/fetch-csv-data (:ifn opts)))
Thanks.
You’re using an old version of tools.cli (probably v0.1.0). For that version it appears that you should use
(required ...)for required options. See the docs at https://github.com/clojure/tools.cli/tree/a741b23f230123179fc518af772f1c057058f7d2In the current version of tools.cli, options are always optional and the optional and required functions are removed.