Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse switches from CLI #186

Closed
wants to merge 5 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions lib/cli.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
defmodule Onigumo.CLI do
def main([component]) do
module = Module.safe_concat("Onigumo", component)
root_path = File.cwd!()
module.main(root_path)
def main(argv) do
{parsed_switches, _, _} =
argv
|> parse_argv

module =
parsed_switches
|> Keyword.get(:component, "Downloader")
|> safe_concat()
nappex marked this conversation as resolved.
Show resolved Hide resolved

parsed_switches
|> Keyword.get(:output, File.cwd!())
|> module.main()
end

defp parse_argv(argv) do
argv
|> OptionParser.parse(
aliases: [o: :output],
strict: [component: :string, output: :string]
)
end

defp safe_concat(component) do
Module.safe_concat("Onigumo", component)
end
end