File tree Expand file tree Collapse file tree 3 files changed +28
-17
lines changed
Expand file tree Collapse file tree 3 files changed +28
-17
lines changed Original file line number Diff line number Diff line change 11# Unreleased
22
3- ## Added
4-
53## Fixed
64
7- ## Changed
5+ - When having named positional arguments and trailing unnamed positional arguments, assign them correctly
86
97# 0.23.93 (2025-02-25 / a192123)
108
Original file line number Diff line number Diff line change 142142 (apply call-handler handler opts args)
143143 (-> opts
144144 (assoc
145- (:key flagspec)
146- (cond
147- (= 0 (count args))
148- (if (contains? flagspec :value )
149- (:value flagspec)
150- ((fnil inc 0 ) (get opts (:key flagspec))))
151- (= 1 (count args))
152- (if (:coll? flagspec)
153- ((fnil conj []) (get opts (:key flagspec)) (first args))
154- (first args))
155- :else
156- (if (:coll? flagspec)
157- ((fnil into []) (get opts (:key flagspec)) args)
158- (vec args))))
145+ (:key flagspec)
146+ (cond
147+ (= 0 (count args))
148+ (if (contains? flagspec :value )
149+ (:value flagspec)
150+ ((fnil inc 0 ) (get opts (:key flagspec))))
151+ (= 1 (count args))
152+ (if (:coll? flagspec)
153+ ((fnil conj []) (get opts (:key flagspec)) (first args))
154+ (first args))
155+ :else
156+ (if (:coll? flagspec)
157+ ((fnil into []) (get opts (:key flagspec)) args)
158+ (vec args))))
159159 (assoc-in [::sources (:key flagspec)] (str (:flag flagspec) " command line flag" ))))))))))))
160160
161161(defn default-parse [s]
451451 (-> cmdspec
452452 (dissoc :command :commands :middleware )
453453 (merge command-match)
454+ (dissoc :argnames )
454455 (assoc :name (str program-name " " cmd)))
455456 (drop arg-count pos-args)
456457 (-> opts
Original file line number Diff line number Diff line change 1818 :flags [" -x" {:doc " flag x"
1919 :required required}]}]})
2020
21+ (defn cmdspec-pos
22+ " cmdspec with a positional argument."
23+ []
24+ {:commands [" run <module>"
25+ {:command #'identity}]})
26+
2127(deftest required-flag
2228 (testing " successful exit"
2329 (are [input args expected]
4753 (is (thrown-with-msg? Exception expected (cli/dispatch* input args)))
4854 (cmdspec-1 true ) [] #"Missing required flags: -x"
4955 (cmdspec-n true ) [" run" ] #"Missing required flags: -x" )))
56+
57+ (deftest positional-argument-with-trailing-arguments
58+ (let [{::cli/keys [argv]
59+ :keys [module]} (cli/dispatch* (cmdspec-pos ) [" run" " foo" " bar" ])]
60+ (is (= " foo" module))
61+ (is (= [" foo" " bar" ] argv))))
You can’t perform that action at this time.
0 commit comments