-
-
Save ngw/7b204dacd80a4e8489e06a73fd3df4d4 to your computer and use it in GitHub Desktop.
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
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