Skip to content

Commit

Permalink
Add *exit-on-error* to avoid termination when executing in REPL
Browse files Browse the repository at this point in the history
Don't call -main from REPL, *exit-on-error* is set true in -main
  • Loading branch information
hisaitami committed Nov 6, 2023
1 parent 6124dc6 commit 4465ca2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tldr.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

(def ^:dynamic *force-color* false)

(def ^:dynamic *exit-on-error* false)

(def tldr-home ".tldrc")

(def zip-file "tldr.zip")
Expand All @@ -35,9 +37,11 @@
distinct)))

(defn die [& args]
(binding [*print-fn* *print-err-fn*]
(println (apply str args)))
(exit 1))
(let [msg (apply str args)]
(if-not *exit-on-error* (throw (js/Error. msg))
(binding [*print-fn* *print-err-fn*]
(println msg)
(exit 1)))))

(defn current-datetime []
(math/ceil (/ (.now js/Date) 1000)))
Expand Down Expand Up @@ -212,6 +216,7 @@
(let [{:keys [options arguments errors summary]} (parse-opts args cli-options)
platform (select-platform options)]

(set! *exit-on-error* true)
(when errors
(die "The following errors occurred while parsing your command:\n\n"
(s/join \newline errors)))
Expand Down

0 comments on commit 4465ca2

Please sign in to comment.