Fix #1695: make CLI args available to REPL (#1697)

This commit is contained in:
Bob 2024-05-26 05:41:47 -04:00 committed by GitHub
parent 5cd2b9d6e6
commit 035a8268ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 4 deletions

View file

@ -12,6 +12,8 @@ A preview of the next release can be installed from
- Fix [#1688](https://github.com/babashka/babashka/issues/1688): use-fixtures should add metadata to `*ns*`
- Fix [#1692](https://github.com/babashka/babashka/issues/1692): Add support for ITransientSet and org.flatland/ordered-set
- Bump org.flatland/ordered to `1.15.12`.
- Partially Fix [#1695](https://github.com/babashka/babashka/issues/1695): `--repl` arg handling should consume only one arg (itself) ([@bobisageek](https://github.com/bobisageek))
- Partially Fix [#1695](https://github.com/babashka/babashka/issues/1695): make `*command-line-args*` value available in the REPL ([@bobisageek](https://github.com/bobisageek))
## 1.3.190 (2024-04-17)

View file

@ -613,7 +613,7 @@ Use bb run --help to show this help output.
:uberjar (first options))))
("--repl")
(let [options (next options)]
(recur (next options)
(recur options
(assoc opts-map
:repl true)))
("--socket-repl")
@ -1021,7 +1021,8 @@ Use bb run --help to show this help output.
doc (print-doc sci-ctx command-line-args)
describe?
[(print-describe) 0]
repl [(repl/start-repl! sci-ctx) 0]
repl (sci/binding [core/command-line-args command-line-args]
[(repl/start-repl! sci-ctx) 0])
nrepl [(start-nrepl! nrepl) 0]
uberjar [nil 0]
list-tasks [(tasks/list-tasks sci-ctx) 0]
@ -1069,7 +1070,8 @@ Use bb run --help to show this help output.
clojure [nil (if-let [proc (bdeps/clojure command-line-args)]
(-> @proc :exit)
0)]
:else [(repl/start-repl! sci-ctx) 0]))
:else (sci/binding [core/command-line-args command-line-args]
[(repl/start-repl! sci-ctx) 0])))
1)]
(flush)
(when uberscript

View file

@ -68,6 +68,10 @@
(is (= {:force? true :repl true} (parse-opts ["--force" "repl"])))
(is (= {:force? true :clojure true :command-line-args '("-M" "-r")}
(parse-opts ["--force" "clojure" "-M" "-r"])))
(is (= {:command-line-args '("asdf" "fdsa")}
(main/parse-opts ["--" "asdf" "fdsa"])))
(is (= {:repl true :command-line-args '("asdf" "fdsa")}
(main/parse-opts ["repl" "--" "asdf" "fdsa"])))
(testing "file opts parsing does not mess with :command-line-args"
(is (= {:prn true, :expressions ["(prn :foo)"]}
(-> (let [[_ opts] (main/parse-file-opt ["-e" "(prn :foo)"] {})]
@ -476,7 +480,11 @@
(deftest command-line-args-test
(is (true? (bb nil "(nil? *command-line-args*)")))
(is (= ["1" "2" "3"] (bb nil "*command-line-args*" "1" "2" "3"))))
(is (= ["1" "2" "3"] (bb nil "*command-line-args*" "1" "2" "3")))
(is (str/includes? (test-utils/bb "*command-line-args*" "repl" "--" "1" "2" "3")
"(\"1\" \"2\" \"3\""))
(is (str/includes? (test-utils/bb "*command-line-args*" "--" "1" "2" "3")
"(\"1\" \"2\" \"3\"")))
(deftest constructors-test
(testing "the clojure.lang.Delay constructor works"