1

I am wondering how I can access the default parameters in my opts, after they've been parased by cli args. I am invoking my program

./rexfer --ifn1 --ifm1 --ofn1 --ofn3

(defn parse-args
  "Using the newer cli library, parses command line args."
  [args]
  (cli args
       ["-r" "--ifn1" ".csv input file"  :default "standfiletrans_acre.csv"]
       ["-p" "--ifn2" ".csv input file"  :default "pp_report_to_change.csv"]
       ["-m" "--ifm1" ".csv input file"  :default "columns.csv"]
       ["-v" "--ofn1" ".csv output file" :default "re_values.csv"]
       ["-x" "--ofn2" ".csv output file" :default "re_pp.csv"]
       ["-u" "--ofn3" ".csv output file" :default "re_mixed_use_ratio.csv"]
       ["-t" "--rpt"  ".csv pipe delimited output file" :default "xfer.csv"]))

(defn -main 
  [& args]
  (let [[opts args banner] (parse-args args)

This is the output of opts after being parsed

{:rpt xfer.csv, :ofn3 re_mixed_use_ratio.csv, :ofn2 re_pp.csv, :ofn1 --ofn3, :ifm1 --ifn1, :ifn2 pp_report_to_change.csv, :ifn1 standfiletrans_acre.csv}

(:ifn1 opts) returns --ifn1, not standfiletrans_acre.csv.

1
  • Looking at the output, (:ifm1 opts) is "--ifn1", (:ifn1 opts) is "standfiletrans_acre.csv" - you're making a mistake somewhere else. Also, if you want to find the issue, it helps if you know the actual args you pass to cli Commented Oct 31, 2012 at 19:36

1 Answer 1

2

The :default keyword is used when the argument is not given at all. If you add the argument, don't supply a value, and then supply the next argument it will read the next argument as the value supplied to the first argument:

arthur@a:~/args/src/args$ lein run --ifn1 --FOO --ifn2 --ifm1  
All namespaces already :aot compiled.
options are:                                                
{:rpt "xfer.csv"
 :ofn3 "re_mixed_use_ratio.csv",
 :ofn2 "re_pp.csv", 
 :ofn1 "re_values.csv",
 :ifm1 "columns.csv", 
 :ifn2 "--ifm1",   
 :ifn1 "--FOO"} 
arguments are: 
[] 
the banner text is: 
 Usage:                             

 Switches    Default                  Desc           
 --------    -------                  ----   
 -r, --ifn1  standfiletrans_acre.csv  .csv input file 
 -p, --ifn2  pp_report_to_change.csv  .csv input file 
 -m, --ifm1  columns.csv              .csv input file   
 -v, --ofn1  re_values.csv            .csv output file 
 -x, --ofn2  re_pp.csv                .csv output file 
 -u, --ofn3  re_mixed_use_ratio.csv   .csv output file                      
 -t, --rpt   xfer.csv                 .csv pipe delimited output file   

In this example the :default value is only used for the values not on the list.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.