Uploaded image for project: 'tools.cli'
  1. TCLI-1

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

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Completed
    • 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

            People

            • Assignee:
              stuart.sierra Stuart Sierra
              Reporter:
              stuart.sierra Stuart Sierra
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: