tools.cli

Do not include keys when no value provided and no :default

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Minor 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}
  1. TCLI-1-0001.patch
    18/May/12 3:37 PM
    2 kB
    Stuart Sierra
  2. TCLI-1-0002.patch
    20/Jul/12 7:41 AM
    2 kB
    Stuart Sierra

Activity

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: