为什么编译tools.cli会导致vector args错误?

时间:2012-08-27 14:26:37

标签: clojure command-line-interface

我从[org.clojure/tools.cli "0.1.0"]移动到0.2.2,但我正在

Exception in thread "main" clojure.lang.ArityException: 
Wrong number of args (2) passed to: PersistentVector

(cli args

开头的行
(defn parse-opts
  "Using the newer cli library, parses command line args."
  [args]
  (cli args
       ["--ifn1" ".csv input file" :default "benetrak_roster.csv"]
       ["--ifn2" ".csv input file" :default "billing_roster.csv"]
       ["--rpt" ".csv pipe delimited output file" :default "bene_gic_rpt.csv"]
       ["--dump1" "text file report for debug output" :default "dumpfile1.txt"]
       ["--dump2" "text file report for debug output" :default "dumpfile2.txt"]
       ["--debug" "Debug flag for logging." :default 0 :parse-fn #(Integer. %)]))

tools.cli就像这样包含(:使用clojure.tools.cli)。

我看不出我做错了什么,并会感激任何指示或帮助。感谢。

顺便说一句,我在查看示例时尝试了以下内容,但它不起作用:

(defn -main 
  [& args]
  (let [[opts args banner]
        (cli args
        ["--ifn1" ".csv input file" :default "benetrak_roster.csv"]
        ["--ifn2" ".csv input file" :default "billing_roster.csv"]
        ["--rpt" ".csv pipe delimited output file" :default "bene_gic_rpt.csv"]
        ["--dump1" "text file report for debug output" :default "dumpfile1.txt"]
        ["--dump2" "text file report for debug output" :default "dumpfile2.txt"]
        ["--debug" "Debug flag for logging." :default 0 :parse-fn #(Integer. %)])
        start-time (str (Date.))]
        .
        .
        .

1 个答案:

答案 0 :(得分:1)

这似乎有效:

(ns test.core
  (:use clojure.tools.cli))

(defn parse-opts
  "Using the newer cli library, parses command line args."
  [args]
  (cli args
       ["--ifn1" ".csv input file" :default "benetrak_roster.csv"]
       ["--ifn2" ".csv input file" :default "billing_roster.csv"]
       ["--rpt" ".csv pipe delimited output file" :default "bene_gic_rpt.csv"]
       ["--dump1" "text file report for debug output" :default "dumpfile1.txt"]
       ["--dump2" "text file report for debug output" :default "dumpfile2.txt"]
       ["--debug" "Debug flag for logging." :default 0 :parse-fn #(Integer. %)]))

test.core> (parse-opts [])
[{:debug 0, :dump2 "dumpfile2.txt", :dump1 "dumpfile1.txt", :rpt "bene_gic_rpt.csv", :ifn2 "billing_roster.csv", :ifn1 "benetrak_roster.csv"} [] "Usage:\n\n Switches  Default              Desc                              \n --------  -------              ----                              \n --ifn1    benetrak_roster.csv  .csv input file                   \n --ifn2    billing_roster.csv   .csv input file                   \n --rpt     bene_gic_rpt.csv     .csv pipe delimited output file   \n --dump1   dumpfile1.txt        text file report for debug output \n --dump2   dumpfile2.txt        text file report for debug output \n --debug   0                    Debug flag for logging.           \n"]
test.core> 

您确定错误不在于您传递给parse-opts的任何内容吗?

另外:你确定你的project.clj中有正确的tools.cli版本(并且只有正确的版本)吗?