Skip to content

Commit

Permalink
Merge pull request #189 from nappex/use-optionParser
Browse files Browse the repository at this point in the history
Use OptionParser to parse component
  • Loading branch information
Glutexo authored Oct 15, 2023
2 parents 67d0c90 + d6232f5 commit 2b2c2ef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/cli.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule Onigumo.CLI do
def main([component]) do
def main(argv) do
{[], [component]} = OptionParser.parse!(argv, strict: [])
module = Module.safe_concat("Onigumo", component)
root_path = File.cwd!()
module.main(root_path)
Expand Down
10 changes: 7 additions & 3 deletions test/onigumo_cli_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@ defmodule OnigumoCLITest do
Onigumo.CLI.main(["Downloader"])
end

test("run CLI with unknown argument") do
test("run CLI with invalid argument") do
assert_raise(ArgumentError, fn -> Onigumo.CLI.main(["Uploader"]) end)
end

test("run CLI with no arguments") do
assert_raise(FunctionClauseError, fn -> Onigumo.CLI.main([]) end)
assert_raise(MatchError, fn -> Onigumo.CLI.main([]) end)
end

test("run CLI with more than one argument") do
assert_raise(FunctionClauseError, fn -> Onigumo.CLI.main(["Downloader", "Parser"]) end)
assert_raise(MatchError, fn -> Onigumo.CLI.main(["Downloader", "Parser"]) end)
end

test("run CLI with invalid switch") do
assert_raise(OptionParser.ParseError, fn -> Onigumo.CLI.main(["--help"]) end)
end
end
end

0 comments on commit 2b2c2ef

Please sign in to comment.