Details
-
Type:
Enhancement
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Completed
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Patch:Code and Test
Description
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}
Attachments
Activity
Stuart Sierra
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Patch | Code and Test [ 10002 ] | |
| Waiting On | gar3thjon3s | |
| Attachment | TCLI-1-0001.patch [ 11229 ] |
Stuart Sierra
made changes -
| Description |
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: {code} (def my-defaults {:foo 1}) (merge my-defaults (first (clojure.tools.cli/cli [] ; no arguments given ["--foo"]))) ; no default specified ;;=> {:foo nil} {code} 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: {code} ;;=> {:foo nil} {code} |
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: {code} (def my-defaults {:foo 1}) (merge my-defaults (first (clojure.tools.cli/cli [] ; no arguments given ["--foo"]))) ; no default specified ;;=> {:foo nil} {code} 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: {code} ;;=> {:foo 1} {code} |
| Attachment | TCLI-1-0002.patch [ 11390 ] |
Stuart Sierra
made changes -
| Resolution | Completed [ 1 ] | |
| Waiting On | gar3thjon3s | |
| Status | Open [ 1 ] | Resolved [ 5 ] |
Stuart Sierra
made changes -
| Status | Resolved [ 5 ] | Closed [ 6 ] |
New patch file 0002 fixes syntax error in the previous patch; updated description to show correct results.