Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Handle --long optargs with leading `=`

Previously, the shell word "--long-opt =foo" was tokenized to

    [:long-opt "--long-opt " "foo"]

This is now parsed as

    [:long-opt "--long-opt =foo"]

Neither of these things are likely to be valid input, but the latter is
less surprising.
  • Loading branch information...
commit a4c9a74dc1f5e07bb57a7af04ccdad3c71cc0486 1 parent e9816bf
@guns guns authored
View
4 src/main/clojure/cljs/tools/cli.cljs
@@ -27,8 +27,8 @@
;; Double dash always ends options processing
#"^--$" (recur opts (into argv cdr) [])
;; Long options with assignment always passes optarg, required or not
- #"^--.+=" (recur (conj opts (into [:long-opt] (s/split car #"=" 2)))
- argv cdr)
+ #"^--\S+=" (recur (conj opts (into [:long-opt] (s/split car #"=" 2)))
+ argv cdr)
;; Long options, consumes cdr head if needed
#"^--" (let [[optarg cdr] (if (contains? required-set car)
[(first cdr) (rest cdr)]
View
4 src/main/clojure/clojure/tools/cli.clj
@@ -27,8 +27,8 @@
;; Double dash always ends options processing
#"^--$" (recur opts (into argv cdr) [])
;; Long options with assignment always passes optarg, required or not
- #"^--.+=" (recur (conj opts (into [:long-opt] (s/split car #"=" 2)))
- argv cdr)
+ #"^--\S+=" (recur (conj opts (into [:long-opt] (s/split car #"=" 2)))
+ argv cdr)
;; Long options, consumes cdr head if needed
#"^--" (let [[optarg cdr] (if (contains? required-set car)
[(first cdr) (rest cdr)]
View
4 src/test/clojure/clojure/tools/cli_test.clj
@@ -21,8 +21,8 @@
(testing "detects arguments to long options"
(is (= (tokenize-args #{"--port" "--host"} ["--port=80" "--host" "example.com"])
[[[:long-opt "--port" "80"] [:long-opt "--host" "example.com"]] []]))
- (is (= (tokenize-args #{} ["--foo=bar" "--noopt="])
- [[[:long-opt "--foo" "bar"] [:long-opt "--noopt" ""]] []])))
+ (is (= (tokenize-args #{} ["--foo=bar" "--noarg=" "--bad =opt"])
+ [[[:long-opt "--foo" "bar"] [:long-opt "--noarg" ""] [:long-opt "--bad =opt"]] []])))
(testing "stops option processing on double dash"
(is (= (tokenize-args #{} ["-a" "--" "-b"])
[[[:short-opt "-a"]] ["-b"]])))
Please sign in to comment.
Something went wrong with that request. Please try again.