From a02d775fc808fc09d6d3b8d6a85f75d7e05e091b Mon Sep 17 00:00:00 2001 From: Bob Date: Sat, 25 May 2024 18:08:06 -0400 Subject: [PATCH] make `*command-line-args*` available to REPL --- src/babashka/main.clj | 6 ++++-- test/babashka/main_test.clj | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 21e2fddf..348802d8 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -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 diff --git a/test/babashka/main_test.clj b/test/babashka/main_test.clj index 39b3667a..26f67290 100644 --- a/test/babashka/main_test.clj +++ b/test/babashka/main_test.clj @@ -480,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"