[#811] Fix --classpath when no additional args are passed
This commit is contained in:
parent
8deb96b931
commit
e26f26c1ba
2 changed files with 158 additions and 155 deletions
|
|
@ -437,34 +437,9 @@ When no eval opts or subcommand is provided, the implicit subcommand is repl.")
|
||||||
("--classpath" "-cp") [(nnext options) (second options)]
|
("--classpath" "-cp") [(nnext options) (second options)]
|
||||||
[options nil])))
|
[options nil])))
|
||||||
|
|
||||||
(defn parse-opts
|
(defn parse-args [args opts-map]
|
||||||
([options] (parse-opts options nil))
|
(loop [options args
|
||||||
([options opts]
|
opts-map opts-map]
|
||||||
(let [[options classpath] (parse-global-opts options)
|
|
||||||
opts (if classpath (assoc opts :classpath classpath)
|
|
||||||
opts)
|
|
||||||
opt (first options)
|
|
||||||
tasks (into #{} (map str) (keys (:tasks @common/bb-edn)))]
|
|
||||||
(when opt
|
|
||||||
;; FILE > TASK > SUBCOMMAND
|
|
||||||
(cond
|
|
||||||
(fs/regular-file? opt)
|
|
||||||
(if (str/ends-with? opt ".jar")
|
|
||||||
{:classpath classpath
|
|
||||||
:jar opt
|
|
||||||
:command-line-args (next options)}
|
|
||||||
{:classpath classpath
|
|
||||||
:file opt
|
|
||||||
:command-line-args (next options)})
|
|
||||||
(contains? tasks opt)
|
|
||||||
{:run opt
|
|
||||||
:classpath classpath
|
|
||||||
:command-line-args (rest options)}
|
|
||||||
(command? opt)
|
|
||||||
(recur (cons (str "--" opt) (next options)) opts)
|
|
||||||
:else
|
|
||||||
(let [opts (loop [options options
|
|
||||||
opts-map opts]
|
|
||||||
(if options
|
(if options
|
||||||
(let [opt (first options)]
|
(let [opt (first options)]
|
||||||
(case opt
|
(case opt
|
||||||
|
|
@ -594,8 +569,35 @@ When no eval opts or subcommand is provided, the implicit subcommand is repl.")
|
||||||
:jar
|
:jar
|
||||||
:file) opt
|
:file) opt
|
||||||
:command-line-args (next options)))))))
|
:command-line-args (next options)))))))
|
||||||
opts-map))]
|
opts-map)))
|
||||||
opts))))))
|
|
||||||
|
(defn parse-opts
|
||||||
|
([options] (parse-opts options nil))
|
||||||
|
([options opts-map]
|
||||||
|
(let [[options classpath] (parse-global-opts options)
|
||||||
|
opts-map (if classpath (assoc opts-map :classpath classpath)
|
||||||
|
opts-map)
|
||||||
|
opt (first options)
|
||||||
|
tasks (into #{} (map str) (keys (:tasks @common/bb-edn)))]
|
||||||
|
(if-not opt opts-map
|
||||||
|
;; FILE > TASK > SUBCOMMAND
|
||||||
|
(cond
|
||||||
|
(fs/regular-file? opt)
|
||||||
|
(if (str/ends-with? opt ".jar")
|
||||||
|
{:classpath classpath
|
||||||
|
:jar opt
|
||||||
|
:command-line-args (next options)}
|
||||||
|
{:classpath classpath
|
||||||
|
:file opt
|
||||||
|
:command-line-args (next options)})
|
||||||
|
(contains? tasks opt)
|
||||||
|
{:run opt
|
||||||
|
:classpath classpath
|
||||||
|
:command-line-args (rest options)}
|
||||||
|
(command? opt)
|
||||||
|
(recur (cons (str "--" opt) (next options)) opts-map)
|
||||||
|
:else
|
||||||
|
(parse-args options opts-map))))))
|
||||||
|
|
||||||
(def env (atom {}))
|
(def env (atom {}))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,8 @@
|
||||||
(is (= '("-e" "1") (bb nil "-e" "*command-line-args*" "--" "-e" "1")))
|
(is (= '("-e" "1") (bb nil "-e" "*command-line-args*" "--" "-e" "1")))
|
||||||
(let [v (bb nil "--describe")]
|
(let [v (bb nil "--describe")]
|
||||||
(is (:babashka/version v))
|
(is (:babashka/version v))
|
||||||
(is (:feature/xml v))))
|
(is (:feature/xml v)))
|
||||||
|
(is (= "src" (:classpath (main/parse-opts ["--classpath" "src"])))))
|
||||||
|
|
||||||
(deftest version-test
|
(deftest version-test
|
||||||
(is (= [1 0 0] (main/parse-version "1.0.0-SNAPSHOT")))
|
(is (= [1 0 0] (main/parse-version "1.0.0-SNAPSHOT")))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue