1

我正在从0.2.2 迁移[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 (:use 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.))]
        .
        .
        .
4

1 回答 1

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(并且只有正确的版本)吗?

于 2012-08-27T16:34:06.317 回答