Slides for brief talk about writing CLI applications with Elixir with sample application
How do you stop?
The default exit value of the program is 0 if the main function returns successfully, and 127 if any errors are encountered. However, you can set the exit status of the program using System.halt.
def cleanup({_options,_args}) do System.halt(0) end
Another useful strategy is to put the pid of the main program and any spawned processes in the options map. You can then notify spawned processes at exit and have them send an all_done message to the main_pid. You can recieve these in your cleanup function to ensure that the program completes before the main process exits.
def cleanup({_options,_args}) do send options[:task_pid], { :finalize } receive do { :all_done } -> System.halt(0) end end