l3nz / cli-matic

Compact, hands-free [sub]command line parsing library for Clojure.
Eclipse Public License 2.0
360 stars 28 forks source link

:default values for :jsonfile options do not parse files #146

Open timgilbert opened 2 years ago

timgilbert commented 2 years ago

Edit: this behavior also holds true for :ednfile options; I didn't test :yamlfile but I imagine it's the same there.

version

0.4.3

platform

JVM 11

problem

:default values for :jsonfile options do not parse files

repro

(require '[cli-matic.core :as c])
;; => nil

;; Using a :jsonfile option the normal way
;; test.json consists of {"abc": 1}

(c/run-cmd* {:command "foo"
             :opts    [{:option "file"
                        :type :jsonfile
                        :default "test.json"}]
             :runs    (fn [args] (clojure.pprint/pprint args))}
            ["--file" "test.json"])

;; Results: 
{:file {"abc" 1}, :_arguments []}

;; Trying to use a default value to specify the filename if the user didn't specify
(c/run-cmd* {:command "foo"
             :opts    [{:option "file"
                        :type :jsonfile
                        :default "test.json"}]
             :runs    (fn [args] (clojure.pprint/pprint args))}
            [])

;; Results:
{:file "test.json", :_arguments []}

expected behavior

clj-matic should parse test.json and return the parsed results

actual behavior

clj-matic just gives me the default filename