How to accept additional arguments for an option in tools.cli?
我是Clojure的新手。
我的cli应用程序的选项
1 | java -jar app.jar -a 12 abc xyz |
第一个是数字,其他两个必须是字符串。
我的代码是:
1 2 3 | ["-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"] |
但是我观察到传递给
其他参数作为
现在,
(1)有没有一种方法可以验证那些未处理的参数?
(2)如何检索和使用这些参数?
我认为您不能一次解析一个选项的空格分隔值。
通常,您可以这样操作:
用逗号分隔它们呢?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | (require '[clojure.tools.cli :refer [parse-opts]]) (def cli-opts [["-a""--add LINE TYPE ENTRY""Add entry to specified line number of the menu" :parse-fn (fn [a-args] (-> a-args (str/split #",") (update 0 #(Integer/parseInt %)))) :validate [(fn [[num s1 s2]] (and (number? num) (string? s1) (string? s2)))]]]) (parse-opts ["-a""12,abc,xyz"] cli-opts) ;;=> {:options {:add [12"abc""xyz"]}, :arguments [], :summary" -a, --add LINE TYPE ENTRY Add entry to specified line number of the menu", :errors nil} |
另一种选择是为