Skip to content

Instantly share code, notes, and snippets.

@jonatanrdsantos
Forked from rin/example.ex
Last active August 29, 2015 14:06
Show Gist options
  • Save jonatanrdsantos/1ee17c735cf848e42b1b to your computer and use it in GitHub Desktop.
Save jonatanrdsantos/1ee17c735cf848e42b1b 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