Rename --verbose to --debug

This commit is contained in:
Michiel Borkent 2021-05-02 11:16:00 +02:00
parent d1bbf844de
commit 6d540e2f06
5 changed files with 22 additions and 21 deletions

View file

@ -15,7 +15,7 @@
babashka.impl.clojure.core.server babashka.impl.clojure.core.server
(:require [babashka.impl.clojure.core :as core] (:require [babashka.impl.clojure.core :as core]
[babashka.impl.clojure.main :as m] [babashka.impl.clojure.main :as m]
[babashka.impl.common :refer [verbose?]] [babashka.impl.common :refer [debug]]
[sci.core :as sci] [sci.core :as sci]
[sci.impl.parser :as p] [sci.impl.parser :as p]
[sci.impl.vars :as vars]) [sci.impl.vars :as vars])
@ -148,7 +148,7 @@
(defn- ex->data (defn- ex->data
[ex phase] [ex phase]
(let [ex (assoc (Throwable->map ex) :phase phase) (let [ex (assoc (Throwable->map ex) :phase phase)
ex (if (not @verbose?) ex (if (not @debug)
(update ex :trace #(vec (take 100 %))) (update ex :trace #(vec (take 100 %)))
ex)] ex)]
ex)) ex))

View file

@ -3,4 +3,4 @@
;; placeholder for ctx ;; placeholder for ctx
(def ctx (volatile! nil)) (def ctx (volatile! nil))
(def bb-edn (volatile! nil)) (def bb-edn (volatile! nil))
(def verbose? (volatile! false)) (def debug (volatile! false))

View file

@ -1,6 +1,6 @@
(ns babashka.impl.tasks (ns babashka.impl.tasks
(:require [babashka.impl.classpath :as cp] (:require [babashka.impl.classpath :as cp]
[babashka.impl.common :refer [ctx bb-edn]] [babashka.impl.common :refer [ctx bb-edn debug]]
[babashka.impl.deps :as deps] [babashka.impl.deps :as deps]
[babashka.process :as p] [babashka.process :as p]
[clojure.java.io :as io] [clojure.java.io :as io]
@ -309,8 +309,9 @@
enter (assoc :enter enter) enter (assoc :enter enter)
leave (assoc :leave leave)) leave (assoc :leave leave))
task parallel? true))] nil])] task parallel? true))] nil])]
(when (= "true" (System/getenv "BABASHKA_DEV")) (when @debug
(.println System/out (ffirst prog))) (binding [*out* *err*]
(println (ffirst prog))))
prog) prog)
[(binding [*out* *err*] [(binding [*out* *err*]
(println "No such task:" task-name)) 1]))) (println "No such task:" task-name)) 1])))

View file

@ -110,20 +110,20 @@
(defn print-help [_ctx _command-line-args] (defn print-help [_ctx _command-line-args]
(println (str "Babashka v" version)) (println (str "Babashka v" version))
(println " (println "
Usage: bb [classpath opts] [eval opts] [cmdline args] Usage: bb [global-opts] [eval opts] [cmdline args]
or: bb [classpath opts] file [cmdline args] or: bb [global-opts] file [cmdline args]
or: bb [classpath opts] subcommand [subcommand opts] [cmdline args] or: bb [global-opts] subcommand [subcommand opts] [cmdline args]
Classpath: Global opts:
-cp, --classpath Classpath to use. Overrides bb.edn classpath. -cp, --classpath Classpath to use. Overrides bb.edn classpath.
--debug Print debug information and internal stacktrace in case of exception.
Evaluation: Evaluation:
-e, --eval <expr> Evaluate an expression. -e, --eval <expr> Evaluate an expression.
-f, --file <path> Evaluate a file. -f, --file <path> Evaluate a file.
-m, --main <ns|var> Call the -main function from a namespace or call a fully qualified var. -m, --main <ns|var> Call the -main function from a namespace or call a fully qualified var.
--verbose Print debug information and entire stacktrace in case of exception.
Help: Help:
@ -567,7 +567,7 @@ When no eval opts or subcommand is provided, the implicit subcommand is repl.")
(if options (if options
(case (first options) (case (first options)
("--classpath" "-cp") (recur (nnext options) (assoc opts-map :classpath (second options))) ("--classpath" "-cp") (recur (nnext options) (assoc opts-map :classpath (second options)))
("--verbose") (recur (next options) (assoc opts-map :verbose? true)) ("--debug") (recur (next options) (assoc opts-map :debug true))
[options opts-map]) [options opts-map])
[options opts-map]))) [options opts-map])))
@ -611,12 +611,12 @@ When no eval opts or subcommand is provided, the implicit subcommand is repl.")
:help :file :command-line-args :help :file :command-line-args
:expressions :stream? :expressions :stream?
:repl :socket-repl :nrepl :repl :socket-repl :nrepl
:verbose? :classpath :debug :classpath
:main :uberscript :describe? :main :uberscript :describe?
:jar :uberjar :clojure :jar :uberjar :clojure
:doc :run :list-tasks]} :doc :run :list-tasks]}
cli-opts cli-opts
_ (when verbose? (vreset! common/verbose? true)) _ (when debug (vreset! common/debug true))
_ (do ;; set properties _ (do ;; set properties
(when main (System/setProperty "babashka.main" main)) (when main (System/setProperty "babashka.main" main))
(System/setProperty "babashka.version" version)) (System/setProperty "babashka.version" version))
@ -708,7 +708,7 @@ When no eval opts or subcommand is provided, the implicit subcommand is repl.")
file (try [[(read-file file)] nil] file (try [[(read-file file)] nil]
(catch Exception e (catch Exception e
(error-handler e {:expression expressions (error-handler e {:expression expressions
:verbose? verbose? :debug debug
:preloads preloads :preloads preloads
:loader (:loader @cp/cp-state)})))) :loader (:loader @cp/cp-state)}))))
expression (str/join " " expressions) ;; this might mess with the locations... expression (str/join " " expressions) ;; this might mess with the locations...
@ -721,7 +721,7 @@ When no eval opts or subcommand is provided, the implicit subcommand is repl.")
(sci/eval-string* sci-ctx preloads) (sci/eval-string* sci-ctx preloads)
(catch Throwable e (catch Throwable e
(error-handler e {:expression expression (error-handler e {:expression expression
:verbose? verbose? :debug debug
:preloads preloads :preloads preloads
:loader (:loader @cp/cp-state)}))))) :loader (:loader @cp/cp-state)})))))
nil)) nil))
@ -771,7 +771,7 @@ When no eval opts or subcommand is provided, the implicit subcommand is repl.")
res))))) res)))))
(catch Throwable e (catch Throwable e
(error-handler e {:expression expression (error-handler e {:expression expression
:verbose? verbose? :debug debug
:preloads preloads :preloads preloads
:loader (:loader @cp/cp-state)})))) :loader (:loader @cp/cp-state)}))))
clojure [nil (if-let [proc (deps/clojure command-line-args)] clojure [nil (if-let [proc (deps/clojure command-line-args)]
@ -794,7 +794,7 @@ When no eval opts or subcommand is provided, the implicit subcommand is repl.")
:jar :uber :jar :uber
:classpath cp :classpath cp
:main-class main :main-class main
:verbose verbose?}) :verbose debug})
(throw (Exception. "The uberjar task needs a classpath.")))) (throw (Exception. "The uberjar task needs a classpath."))))
exit-code)))) exit-code))))

View file

@ -37,10 +37,10 @@
(main/parse-opts ["--classpath" "src" "uberjar" "foo.jar"]))) (main/parse-opts ["--classpath" "src" "uberjar" "foo.jar"])))
(is (= {:classpath "src" (is (= {:classpath "src"
:uberjar "foo.jar" :uberjar "foo.jar"
:verbose? true} :debug true}
(main/parse-opts ["--verbose" "--classpath" "src" "uberjar" "foo.jar"]))) (main/parse-opts ["--debug" "--classpath" "src" "uberjar" "foo.jar"])))
(is (= "src" (:classpath (main/parse-opts ["--classpath" "src"])))) (is (= "src" (:classpath (main/parse-opts ["--classpath" "src"]))))
(is (:verbose? (main/parse-opts ["--verbose"]))) (is (:debug (main/parse-opts ["--debug"])))
(is (= 123 (bb nil "(println 123)"))) (is (= 123 (bb nil "(println 123)")))
(is (= 123 (bb nil "-e" "(println 123)"))) (is (= 123 (bb nil "-e" "(println 123)")))
(is (= 123 (bb nil "--eval" "(println 123)"))) (is (= 123 (bb nil "--eval" "(println 123)")))