Here's a solution to the problem I was trying to solve. I'm not happy with it (the definition of has-repl?), but it's working for now.
It's also Sun/Oracle JVM specific with the sun.java.command clause.
Again, the problem is that I wanted an exit routine I could call that wouldn't terminate the jvm when I'm running -main from the REPL, but that otherwise calls System/exit when running as an uberjar.
Other suggestions welcome.
(defn has-repl?
"Return true if we appear to be running with a REPL, false otherwise."
[]
;; *TBD*: Consider looking for some particular repl routine in jvm stack traces
;; Don't care about the clojure.* prop vals, just that the property exists.
(if (or (System/getProperty "clojure.debug")
(System/getProperty "clojure.compile.path")
(if-let [command (System/getProperty "sun.java.command")]
(.contains command "clojure.main")))
true
false))
(defn- exit [status & [msg]]
(when msg
(println msg))
(flush)
(if (has-repl?)
(throw (ex-info msg {:repl-exit true :status status}))
(System/exit status)))
...