File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010 " given a matched option and whatever is after it in the arg list, remove the option
1111 and return [{opt-key opt-value} remaining-args]"
1212 [[switch val & rest :as args] spec]
13- (if ( and switch val)
14- [{( :key spec) val} rest]
15- [{} args]))
16-
13+ (let [parser ( or ( :parser spec) identity)]
14+ ( if ( and switch val)
15+ [{( :key spec) ( parser val)} rest]
16+ [{} args])))
1717
1818(defn parse-args
1919 " do a partial parse of args... removing only options we know about and leaving everything else to
3131 [{:key :version
3232 :matcher #{" -v" " -version" " --version" }}
3333 {:key :config
34- :matcher #{" -c" " -config" " --config" }}])
34+ :matcher #{" -c" " -config" " --config" }
35+ :parser symbol}])
3536
3637(defn parse-migrate-args
3738 [args]
3839 (parse-args args migrate-arg-specs))
3940
4041(def create-migration-arg-specs
4142 [{:key :config
42- :matcher #{" -c" " -config" " --config" }}])
43+ :matcher #{" -c" " -config" " --config" }
44+ :parser symbol}])
4345
4446(defn parse-create-migration-args
4547 [args]
Original file line number Diff line number Diff line change 2626
2727(deftest test-parse-migrate-args
2828 (is (= (parse-migrate-args [" foo" " --other" " blah" " -v" " 10" " bar" " --config" " conf" " baz" ])
29- [{:version " 10" :config " conf" } [" foo" " --other" " blah" " bar" " baz" ]])))
29+ [{:version " 10" :config ' conf} [" foo" " --other" " blah" " bar" " baz" ]])))
3030
3131(deftest test-parse-create-migration-args
3232 (is (= (parse-create-migration-args [" foo" " --other" " blah" " -v" " 10" " bar" " --config" " conf" " baz" ])
33- [{:config " conf" } [" foo" " --other" " blah" " -v" " 10" " bar" " baz" ]])))
33+ [{:config ' conf} [" foo" " --other" " blah" " -v" " 10" " bar" " baz" ]])))
You can’t perform that action at this time.
0 commit comments