Skip to content

Instantly share code, notes, and snippets.

@ngw

ngw/cli.ex Secret

Created July 10, 2016 13:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngw/7b204dacd80a4e8489e06a73fd3df4d4 to your computer and use it in GitHub Desktop.
Save ngw/7b204dacd80a4e8489e06a73fd3df4d4 to your computer and use it in GitHub Desktop.
defmodule Pince.CLI do
@moduledoc """
Usage pince --from path --to path
"""
def main(argv) do
argv
|> parse_args
|> process
end
@doc """
`argv` can be -h or --help which returns :help and can also be --from or -f which sets where the
Pince project resides and --to or -t which sets the target path
"""
def parse_args(argv) do
parse = OptionParser.parse(argv, switches: [ help: :boolean,
from: :string ,
to: :string ],
aliases: [ h: :help,
f: :from,
t: :to ])
case parse do
{ [ help: true ], _, _ } -> :help
{ options , _, _ } -> Keyword.put_new(options, :from, ".")
end
end
@doc """
Displays a help message.
"""
def process(:help) do
IO.puts @moduledoc
System.halt(0)
end
def process(options) do
Pince.Site.process(options)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment