-
-
Save jonatanrdsantos/1ee17c735cf848e42b1b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
defmodule Example do | |
def main(args) do | |
args |> parse_args |> process | |
end | |
def parse_args(args) do | |
options = OptionParser.parse(args, switches: [help: :boolean], | |
aliases: [h: :help]) | |
case options do | |
{ [ help: true], _} -> :help | |
{ _, [ vehicle ] } -> [vehicle, "eels"] | |
{ _, [ vehicle, fish ] } -> [vehicle, fish] | |
_ -> :help | |
end | |
end | |
def process([vehicle, fish]) do | |
IO.puts "My #{vehicle} is full of #{fish}." | |
end | |
def process(:help) do | |
IO.puts """ | |
Usage: | |
example [vehicle] [fish] | |
Options: | |
-h, [--help] # Show this help message and quit. | |
Description: | |
Excuse me, dear Sir, are there fish in your vehicle? | |
""" | |
System.halt(0) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment