Created
May 28, 2016 11:32
-
-
Save q231950/db48b32077c85d28463479a2173a0e70 to your computer and use it in GitHub Desktop.
Parse arguments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(argv) do | |
argv | |
|> parse_args | |
|> process | |
end | |
def parse_args(argv) do | |
parse = OptionParser.parse(argv, switches: [ help: :boolean], | |
aliases: [ h: :help ]) | |
case parse do | |
{ [ help: true ], _, _ } | |
-> :help | |
{ _, [ user, project, count ], _ } | |
-> { user, project, String.to_integer(count) } | |
{ _, [ user, project ], _ } | |
-> { user, project, @default_count } | |
_ -> :help | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment