This commit is contained in:
Michiel Borkent 2021-03-30 18:06:56 +02:00
parent 02cecb259d
commit 6a7baf2a90
3 changed files with 18 additions and 13 deletions

View file

@ -1 +1 @@
0.3.1-SNAPSHOT 0.3.1

View file

@ -111,7 +111,7 @@ or: bb [classpath opts] subcommand [subcommand opts] [cmdline args]
Classpath: Classpath:
-cp, --classpath Classpath to use. -cp, --classpath Classpath to use. Overrides bb.edn classpath.
Evaluation: Evaluation:
@ -562,8 +562,16 @@ When no eval opts or subcommand is provided, the implicit subcommand is repl.")
uberscript-sources (atom ()) uberscript-sources (atom ())
classpath (or classpath classpath (or classpath
(System/getenv "BABASHKA_CLASSPATH")) (System/getenv "BABASHKA_CLASSPATH"))
_ (when classpath _ (if classpath
(cp/add-classpath classpath)) (cp/add-classpath classpath)
;; when classpath isn't set, we calculate it from bb.edn, if present
(let [bb-edn-file (or (System/getenv "BABASHKA_EDN")
"bb.edn")]
(when (fs/exists? bb-edn-file)
(let [edn (edn/read-string (slurp bb-edn-file))]
(vreset! bb-edn edn)))
;; we mutate the atom from tests as well, so despite the above it can contain a bb.edn
(when-let [bb-edn @bb-edn] (deps/add-deps bb-edn))))
abs-path (when file abs-path (when file
(let [abs-path (.getAbsolutePath (io/file file))] (let [abs-path (.getAbsolutePath (io/file file))]
(vars/bindRoot sci/file abs-path) (vars/bindRoot sci/file abs-path)
@ -715,13 +723,6 @@ When no eval opts or subcommand is provided, the implicit subcommand is repl.")
exit-code)))) exit-code))))
(defn main [& args] (defn main [& args]
(let [bb-edn-file (or (System/getenv "BABASHKA_EDN")
"bb.edn")]
(when (fs/exists? bb-edn-file)
(let [edn (edn/read-string (slurp bb-edn-file))]
(vreset! bb-edn edn)))
;; we mutate the atom from tests as well, so despite the above it can contain a bb.edn
(when-let [bb-edn @bb-edn] (deps/add-deps bb-edn)))
(let [opts (parse-opts args)] (let [opts (parse-opts args)]
(exec opts))) (exec opts)))

View file

@ -4,7 +4,7 @@
[babashka.test-utils :as test-utils] [babashka.test-utils :as test-utils]
[clojure.edn :as edn] [clojure.edn :as edn]
[clojure.string :as str] [clojure.string :as str]
[clojure.test :as test :refer [deftest is]])) [clojure.test :as test :refer [deftest is testing]]))
(defn bb [& args] (defn bb [& args]
(edn/read-string (edn/read-string
@ -35,7 +35,11 @@
(deftest deps-test (deftest deps-test
(with-config '{:deps {medley/medley {:mvn/version "1.3.0"}}} (with-config '{:deps {medley/medley {:mvn/version "1.3.0"}}}
(is (= '{1 {:id 1}, 2 {:id 2}} (is (= '{1 {:id 1}, 2 {:id 2}}
(bb "-e" "(require 'medley.core)" "-e" "(medley.core/index-by :id [{:id 1} {:id 2}])"))))) (bb "-e" "(require 'medley.core)" "-e" "(medley.core/index-by :id [{:id 1} {:id 2}])"))))
(testing "--classpath option overrides bb.edn"
(with-config '{:deps {medley/medley {:mvn/version "1.3.0"}}}
(is (= "src"
(bb "-cp" "src" "-e" "(babashka.classpath/get-classpath)"))))))
;; TODO: ;; TODO:
;; Do we want to support the same parsing as the clj CLI? ;; Do we want to support the same parsing as the clj CLI?