File tree Expand file tree Collapse file tree 2 files changed +14
-7
lines changed Expand file tree Collapse file tree 2 files changed +14
-7
lines changed Original file line number Diff line number Diff line change 133
133
(let [cli-args (mapv (partial apply argspec->cli-argspec) argspecs)]
134
134
(:summary (cli/parse-opts [] cli-args))))
135
135
136
+ (defn split-args [args]
137
+ (loop [kw {} cli [] [arg & more] args]
138
+ (if-not arg
139
+ {:kw kw :cli cli}
140
+ (if-not (keyword? arg)
141
+ (recur kw (conj cli arg) more)
142
+ (recur (assoc kw arg (first more)) cli (rest more))))))
143
+
136
144
(defmacro clifn [doc argspecs & body]
137
145
(assert (string? doc) " missing docstring" )
138
146
(let [doc (string/replace doc #"\n " " \n " )
146
154
varmeta {:doc clj-doc :arglists arglists :argspec cli-args}]
147
155
`(->
148
156
(fn [& args#]
149
- (let [cli?# ( every? string? args#)
150
- parsed# (when cli?# ( cli /parse-opts args # ~cli-args) )
151
- ~bindings (if-not cli?# args # (:options parsed#))
152
- ~'*args* (when cli?# ( :arguments parsed#) )]
157
+ (let [{kws# :kw clis# :cli } ( split-args args#)
158
+ parsed# (cli/parse-opts clis # ~cli-args)
159
+ ~bindings (merge kws # (:options parsed#))
160
+ ~'*args* (:arguments parsed#)]
153
161
~@(mapv (partial apply argspec->assert) argspecs)
154
162
(if-not ~'help (do ~@body) (print ~cli-doc))))
155
163
(with-meta ~varmeta))))
Original file line number Diff line number Diff line change 261
261
(when-not (and op (:boot.core/task (meta op)))
262
262
(throw (IllegalArgumentException. (format " No such task (%s)" op-str))))
263
263
(let [spec (:argspec (meta op))
264
- parsed (cli/parse-opts args spec :in-order true )
265
- opts (->> parsed :options (mapcat identity))]
264
+ parsed (cli/parse-opts args spec :in-order true )]
266
265
(when (seq (:errors parsed))
267
266
(throw (IllegalArgumentException. (string/join " \n " (:errors parsed)))))
268
- (recur (conj ret (apply (var-get op) opts )) (:arguments parsed)))))))
267
+ (recur (conj ret (apply (var-get op) args )) (:arguments parsed)))))))
269
268
270
269
(def ^:dynamic *warnings* nil )
271
270
You can’t perform that action at this time.
0 commit comments