Skip to content

Commit

Permalink
Add io.aviso.repl/-main
Browse files Browse the repository at this point in the history
  • Loading branch information
hlship committed Oct 20, 2022
1 parent 127982e commit 30392ef
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
10 changes: 10 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

The default stack frame filter now terminates at any `speclj.*` namespace.

The `io.aviso.ansi` namespace now determines whether output is connected to a terminal,
and disables fonts and colors if so; this can be overridden with the `ENABLE_ANSI_COLORS`
environment variable.

Added a `-main` function to `io.aviso.repl`; this installs pretty exceptions before delegating
to `clojure.main/main`. Thus, `clojure -m io.aviso.repl -m org.example.myapp` will ultimately
pass any remaining command line arguments to `org.example.myapp/-main`.

The pretty replacement for `clojure.repl/pst` now writes to `*err*`, not `*out*`.

## 1.2 -- 30 Sep 2022

Output from `write-exception` is now buffered; this should reduce the
Expand Down
3 changes: 3 additions & 0 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
com.walmartlabs/test-reporting {:mvn/version "1.2"}
org.clojure/core.async {:mvn/version "1.5.648"}}}

:main
{:main-opts ["-m" "io.aviso.repl"]}

:demo
{:main-opts ["-m" "demo"]}}}
14 changes: 11 additions & 3 deletions src/io/aviso/repl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
(if (instance? Throwable e-or-depth)
(print-exception e-or-depth nil)
(pretty-pst *e e-or-depth)))
([e depth] (print-exception e {:frame-limit depth})))
([e depth]
(binding [*out* *err*]
(print-exception e {:frame-limit depth}))))

(defn pretty-print-stack-trace
"Replacement for `clojure.stacktrace/print-stack-trace` and `print-cause-trace`. These functions are used by `clojure.test`."
Expand All @@ -66,8 +68,6 @@
Caught exceptions do not print the stack trace; the pst replacement does."
[]
;; TODO: Not exactly sure why this works, because clojure.main/repl should be resolving the var to its contained
;; function, so the override should not be visible. I'm missing something.
(reset-var! #'main/repl-caught pretty-repl-caught)
(reset-var! #'repl/pst pretty-pst)
(reset-var! #'st/print-stack-trace pretty-print-stack-trace)
Expand Down Expand Up @@ -128,3 +128,11 @@
(-> text
(e/parse-exception nil)
e/format-exception)))


(defn -main
"Installs pretty exceptions, then delegates to clojure.main/main."
{:added "1.3.0"}
[& args]
(install-pretty-exceptions)
(apply main/main args))
3 changes: 2 additions & 1 deletion test/demo.clj
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
[]
(report {:type :error :expected nil :actual (make-ex-info)}))

(defn -main [& _]
(defn -main [& args]
(prn `-main :args args)
(println "Installing pretty exceptions ...")
(repl/install-pretty-exceptions)
(println (ansi/bold-green "ok"))
Expand Down

0 comments on commit 30392ef

Please sign in to comment.