Skip to content

Instantly share code, notes, and snippets.

@rin
Created September 1, 2013 09:56
Show Gist options
  • Save rin/6403419 to your computer and use it in GitHub Desktop.
Save rin/6403419 to your computer and use it in GitHub Desktop.
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