[TCLI-1] Do not include keys when no value provided and no :default Created: 18/May/12  Updated: 24/Aug/12  Resolved: 24/Aug/12

Status: Closed
Project: tools.cli
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Enhancement Priority: Minor
Reporter: Stuart Sierra Assignee: Stuart Sierra
Resolution: Completed Votes: 0
Labels: None

Attachments: Text File TCLI-1-0001.patch     Text File TCLI-1-0002.patch    
Patch: Code and Test


I was trying to use tools.cli in conjunction with a configuration map
loaded from a file, and use clojure.core/merge to combine the results.

This didn't work because tools.cli always uses a default value of
nil, even when no default value is specified. The nil always
overrides defaults from another source.

Example before the patch:

(def my-defaults
  {:foo 1})

(merge my-defaults
       (first (clojure.tools.cli/cli
               [] ; no arguments given
               ["--foo"]))) ; no default specified
;;=> {:foo nil}

This enhancement modifies tools.cli to completely omit arguments which
have no default specified and no value given on the command line.

After the patch, the above example returns:

;;=> {:foo 1}

Comment by Stuart Sierra [ 20/Jul/12 7:41 AM ]

New patch file 0002 fixes syntax error in the previous patch; updated description to show correct results.

Comment by Stuart Sierra [ 24/Aug/12 8:31 AM ]

Patch applied in commit https://github.com/clojure/tools.cli/commit/f9d92395cb788dd08cb144035a9d5fd8706d10b5

Generated at Sat Mar 23 03:32:06 CDT 2019 using JIRA 4.4#649-r158309.