Skip to content

Instantly share code, notes, and snippets.

@bluegraybox
Created August 14, 2011 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bluegraybox/1145126 to your computer and use it in GitHub Desktop.
Save bluegraybox/1145126 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