Skip to content

Instantly share code, notes, and snippets.

@izinin
Forked from bluegraybox/options.erl
Created September 22, 2022 18:58
Show Gist options
  • Save izinin/63f0a390c5d7261a8f9a6fb594cc1307 to your computer and use it in GitHub Desktop.
Save izinin/63f0a390c5d7261a8f9a6fb594cc1307 to your computer and use it in GitHub Desktop.
Erlang command-line option handling
#!/usr/bin/escript
-module(options).
% main/1 calls main/3 with default values
main(Args) -> main(false, "", Args).
main(_, _, ["-h" | _ ] ) -> io:format("Help text...~n"); % help
main(_, Value, ["-f" | Args ] ) -> main(true, Value, Args); % set flag
main(Flag, _, ["-v", Value | Args ] ) -> main(Flag, Value, Args); % set value
main(Flag, Value, Args) -> do_stuff(Flag, Value, Args). % go!
do_stuff(Flag, Value, Args) ->
%% Do stuff
ok.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment