diff --git a/CHANGELOG.md b/CHANGELOG.md index 82525ff3..951f4142 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ A preview of the next release can be installed from - 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)) +- Fix [#1686](https://github.com/babashka/babashka/issues/1686): do not fetch dependencies/invoke java for `version`, `help`, and `describe` options ([@bobisageek](https://github.com/bobisageek)) ## 1.3.190 (2024-04-17) diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 348802d8..e310c1fc 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -139,7 +139,7 @@ (binding [*out* *err*] (apply println msgs))) -(defn print-help [_ctx _command-line-args] +(defn print-help [] (println (str "Babashka v" version)) (println " Usage: bb [svm-opts] [global-opts] [eval opts] [cmdline args] @@ -215,8 +215,7 @@ Tooling: File names take precedence over subcommand names. Remaining arguments are bound to *command-line-args*. Use -- to separate script command line args from bb command line args. -When no eval opts or subcommand is provided, the implicit subcommand is repl.") - [nil 0]) +When no eval opts or subcommand is provided, the implicit subcommand is repl.")) (defn print-doc [ctx command-line-args] (let [arg (first command-line-args) @@ -832,13 +831,12 @@ Use bb run --help to show this help output. sci/print-length @sci/print-length ;; when adding vars here, also add them to repl.clj and nrepl_server.clj ] - (let [{version-opt :version - :keys [:shell-in :edn-in :shell-out :edn-out - :help :file :command-line-args + (let [{:keys [:shell-in :edn-in :shell-out :edn-out + :file :command-line-args :expressions :stream? :init :repl :socket-repl :nrepl :debug :classpath :force? - :main :uberscript :describe? + :main :uberscript :jar :uberjar :clojure :doc :run :list-tasks :print-deps :prepare] @@ -1015,12 +1013,7 @@ Use bb run --help to show this help output. exit-code (or exit-code (second - (cond version-opt - [(print-version) 0] - help (print-help sci-ctx command-line-args) - doc (print-doc sci-ctx command-line-args) - describe? - [(print-describe) 0] + (cond doc (print-doc sci-ctx command-line-args) repl (sci/binding [core/command-line-args command-line-args] [(repl/start-repl! sci-ctx) 0]) nrepl [(start-nrepl! nrepl) 0] @@ -1109,6 +1102,15 @@ Use bb run --help to show this help output. (uberjar/run uber-params)))))) exit-code)))) +(defn exec-without-deps [cli-opts] + (let [{version-opt :version + :keys [help describe?]} cli-opts] + (cond + version-opt (print-version) + help (print-help) + describe? (print-describe))) + 0) + (defn satisfies-min-version? [min-version] (let [[major-current minor-current patch-current] version-data [major-min minor-min patch-min] (parse-version min-version)] @@ -1149,6 +1151,10 @@ Use bb run --help to show this help output. (str (fs/real-path f)) f)) +(defn deps-not-needed [opts] + (let [fast-path-opts [:version :help :describe?]] + (some #(contains? opts %) fast-path-opts))) + (defn main [& args] (let [bin-jar (binary-invoked-as-jar) args (if bin-jar @@ -1205,7 +1211,9 @@ Use bb run --help to show this help output. (binding [*out* *err*] (println (str "WARNING: this project requires babashka " min-bb-version " or newer, but you have: " version))))) - (exec opts))) + (if (deps-not-needed opts) + (exec-without-deps opts) + (exec opts)))) (def musl? "Captured at compile time, to know if we are running inside a diff --git a/test/babashka/main_test.clj b/test/babashka/main_test.clj index 26f67290..53683a20 100644 --- a/test/babashka/main_test.clj +++ b/test/babashka/main_test.clj @@ -88,6 +88,18 @@ (is (not (main/satisfies-min-version? "300.0.0"))) (is (not (main/satisfies-min-version? "300.0.0-SNAPSHOT")))) +(deftest version-opt-test + (is (str/starts-with? (test-utils/bb nil "version") + "babashka v"))) + +(deftest help-opt-test + (is (every? #(str/includes? (test-utils/bb nil "help") %) + ["Babashka v" "Help:"]))) + +(deftest describe-opt-test + (is (every? (partial contains? (bb nil "describe")) + [:babashka/version :feature/yaml :feature/logging]))) + (deftest print-error-test (is (thrown-with-msg? Exception #"java.lang.NullPointerException" (bb nil "(subs nil 0 0)"))))