I'm a Clojure newbie.
I need multiple arguments for option -a of my cli app, like:
java -jar app.jar -a 12 abc xyz
First one is a number, and other two have to be strings.
My code is:
["-a" "--add LINE TYPE ENTRY" "Add entry to specified line number of the menu"
:parse-fn #(split % #" ")
:validate [#(number? (Integer/parseInt (first %))) "ERROR: Invalid position"]
But I observed the % passed to :parse-fn function to be a vector containing only the first argument, i.e., [12]
the other arguments are listed as value of the key :arguments of the map returned by parse-opts
Now,
(1) Is there a way to validate those unprocessed arguments?
(2) How will I retrieve and use those arguments?
I think you cannot parse white-space separated values for one option at a time. Normally you would do it like this:
-a opt1 -a opt2 -a opt3, but since you have a different type foropt1this will not work.What about separating them by comma?
Another option would be to introduce two or three different options for
a:--line,--typeand--entry.