James, All well and good, but you still need to know if you're running in a
REPL environment, and make sure you do NOT call System/exit for any
(typical) reason in that environment.  The idea is to test your (-main)
function from the REPL, without having to restart the lisp every time.


On Thu, May 8, 2014 at 10:28 AM, James Reeves <ja...@booleanknot.com> wrote:

> Sure, but those return codes correspond to some ending state of your
> application, which can occur via a normal function return, or through an
> exception. In both cases, your -main function can map state to exit code.
>
> For instance, let's assume that your application will return or except. In
> example below I'm using Slingshot to handle the exceptions:
>
> (defn -main [& args]
>   (try+
>     (apply app args) (System/exit 0)
>     (catch [:exit :app/bad-data] _ (System/exit 1))
>     (catch [:exit :app/connect-failed] _ (System/exit 2))))
>
>
> Alternatively, if the app function returns the status rather than excepts:
>
> (defn -main [& args]
>   (System/exit
>    (case (apply app args)
>      :app/ok 0
>      :app/bad-data 1
>      :app/connect-failed 2)))
>
>
> - James
>
>
>
> On 8 May 2014 14:23, Dave Tenny <dave.te...@gmail.com> wrote:
>
>> When running as an uberjar, i.e. "java -jar myapp.jar [args]"
>> the return code of the process to the shell is very important.
>> System/exit is how that return code is sent.
>>
>>
>> On Thu, May 8, 2014 at 9:20 AM, James Reeves <ja...@booleanknot.com>wrote:
>>
>>> Having your application call System/exit directly is often indicative of
>>> some unnecessary coupling in your code.
>>>
>>> Under what circumstances does your application need to exit?
>>>
>>> - James
>>>
>>>
>>> On 22 April 2014 17:59, Dave Tenny <dave.te...@gmail.com> wrote:
>>>
>>>> I have an app I'm building.  It calls System/exit.  That doesn't works
>>>> so well if I'm debugging in the REPL however.
>>>>
>>>> What's the preferred method of determining whether I'm in REPL mode
>>>> interaction vs running as a standalone app?
>>>>
>>>> Also, long as I'm asking and being lazy, does the -main function return
>>>> value translate to a System/exit value if it's numeric?
>>>> Or is System/exit the way to go?
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Clojure" group.
>>>> To post to this group, send email to clojure@googlegroups.com
>>>> Note that posts from new members are moderated - please be patient with
>>>> your first post.
>>>> To unsubscribe from this group, send email to
>>>> clojure+unsubscr...@googlegroups.com
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/clojure?hl=en
>>>> ---
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Clojure" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to clojure+unsubscr...@googlegroups.com.
>>>>
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to this group, send email to clojure@googlegroups.com
>>> Note that posts from new members are moderated - please be patient with
>>> your first post.
>>> To unsubscribe from this group, send email to
>>> clojure+unsubscr...@googlegroups.com
>>> For more options, visit this group at
>>> http://groups.google.com/group/clojure?hl=en
>>> ---
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "Clojure" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/clojure/KZJQsmOeiHc/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> clojure+unsubscr...@googlegroups.com.
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "Clojure" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/clojure/KZJQsmOeiHc/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to