From 6d540e2f06acf086adebb2153e1b68a640e64012 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Sun, 2 May 2021 11:16:00 +0200 Subject: [PATCH] Rename --verbose to --debug --- src/babashka/impl/clojure/core/server.clj | 4 ++-- src/babashka/impl/common.clj | 2 +- src/babashka/impl/tasks.clj | 7 ++++--- src/babashka/main.clj | 24 +++++++++++------------ test/babashka/main_test.clj | 6 +++--- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/babashka/impl/clojure/core/server.clj b/src/babashka/impl/clojure/core/server.clj index 35d1e17e..6211d7a5 100644 --- a/src/babashka/impl/clojure/core/server.clj +++ b/src/babashka/impl/clojure/core/server.clj @@ -15,7 +15,7 @@ babashka.impl.clojure.core.server (:require [babashka.impl.clojure.core :as core] [babashka.impl.clojure.main :as m] - [babashka.impl.common :refer [verbose?]] + [babashka.impl.common :refer [debug]] [sci.core :as sci] [sci.impl.parser :as p] [sci.impl.vars :as vars]) @@ -148,7 +148,7 @@ (defn- ex->data [ex phase] (let [ex (assoc (Throwable->map ex) :phase phase) - ex (if (not @verbose?) + ex (if (not @debug) (update ex :trace #(vec (take 100 %))) ex)] ex)) diff --git a/src/babashka/impl/common.clj b/src/babashka/impl/common.clj index 3fa52fb2..9cf5c2a2 100644 --- a/src/babashka/impl/common.clj +++ b/src/babashka/impl/common.clj @@ -3,4 +3,4 @@ ;; placeholder for ctx (def ctx (volatile! nil)) (def bb-edn (volatile! nil)) -(def verbose? (volatile! false)) +(def debug (volatile! false)) diff --git a/src/babashka/impl/tasks.clj b/src/babashka/impl/tasks.clj index ca879b5b..758fbadc 100644 --- a/src/babashka/impl/tasks.clj +++ b/src/babashka/impl/tasks.clj @@ -1,6 +1,6 @@ (ns babashka.impl.tasks (: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.process :as p] [clojure.java.io :as io] @@ -309,8 +309,9 @@ enter (assoc :enter enter) leave (assoc :leave leave)) task parallel? true))] nil])] - (when (= "true" (System/getenv "BABASHKA_DEV")) - (.println System/out (ffirst prog))) + (when @debug + (binding [*out* *err*] + (println (ffirst prog)))) prog) [(binding [*out* *err*] (println "No such task:" task-name)) 1]))) diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 338b02b1..4081d202 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -110,20 +110,20 @@ (defn print-help [_ctx _command-line-args] (println (str "Babashka v" version)) (println " -Usage: bb [classpath opts] [eval opts] [cmdline args] -or: bb [classpath opts] file [cmdline args] -or: bb [classpath opts] subcommand [subcommand opts] [cmdline args] +Usage: bb [global-opts] [eval opts] [cmdline args] +or: bb [global-opts] file [cmdline args] +or: bb [global-opts] subcommand [subcommand opts] [cmdline args] -Classpath: +Global opts: -cp, --classpath Classpath to use. Overrides bb.edn classpath. + --debug Print debug information and internal stacktrace in case of exception. Evaluation: -e, --eval Evaluate an expression. -f, --file Evaluate a file. -m, --main 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: @@ -567,7 +567,7 @@ When no eval opts or subcommand is provided, the implicit subcommand is repl.") (if options (case (first 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]))) @@ -611,12 +611,12 @@ When no eval opts or subcommand is provided, the implicit subcommand is repl.") :help :file :command-line-args :expressions :stream? :repl :socket-repl :nrepl - :verbose? :classpath + :debug :classpath :main :uberscript :describe? :jar :uberjar :clojure :doc :run :list-tasks]} cli-opts - _ (when verbose? (vreset! common/verbose? true)) + _ (when debug (vreset! common/debug true)) _ (do ;; set properties (when main (System/setProperty "babashka.main" main)) (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] (catch Exception e (error-handler e {:expression expressions - :verbose? verbose? + :debug debug :preloads preloads :loader (:loader @cp/cp-state)})))) 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) (catch Throwable e (error-handler e {:expression expression - :verbose? verbose? + :debug debug :preloads preloads :loader (:loader @cp/cp-state)}))))) nil)) @@ -771,7 +771,7 @@ When no eval opts or subcommand is provided, the implicit subcommand is repl.") res))))) (catch Throwable e (error-handler e {:expression expression - :verbose? verbose? + :debug debug :preloads preloads :loader (:loader @cp/cp-state)})))) 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 :classpath cp :main-class main - :verbose verbose?}) + :verbose debug}) (throw (Exception. "The uberjar task needs a classpath.")))) exit-code)))) diff --git a/test/babashka/main_test.clj b/test/babashka/main_test.clj index 6d750ca9..ddabbe3c 100644 --- a/test/babashka/main_test.clj +++ b/test/babashka/main_test.clj @@ -37,10 +37,10 @@ (main/parse-opts ["--classpath" "src" "uberjar" "foo.jar"]))) (is (= {:classpath "src" :uberjar "foo.jar" - :verbose? true} - (main/parse-opts ["--verbose" "--classpath" "src" "uberjar" "foo.jar"]))) + :debug true} + (main/parse-opts ["--debug" "--classpath" "src" "uberjar" "foo.jar"]))) (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 "-e" "(println 123)"))) (is (= 123 (bb nil "--eval" "(println 123)")))