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
(: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))

View file

@ -3,4 +3,4 @@
;; placeholder for ctx
(def ctx (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
(: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])))

View file

@ -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 <expr> Evaluate an expression.
-f, --file <path> Evaluate a file.
-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:
@ -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))))

View file

@ -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)")))