Skip to content

Commit

Permalink
Merge pull request #199 from Glutexo/component
Browse files Browse the repository at this point in the history
Use Map instead of Module.safe_concat
  • Loading branch information
Glutexo authored Nov 4, 2023
2 parents 2b2c2ef + fffc5d3 commit 4874162
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/cli.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
defmodule Onigumo.CLI do
@components %{
:Downloader => Onigumo.Downloader
}

def main(argv) do
{[], [component]} = OptionParser.parse!(argv, strict: [])
module = Module.safe_concat("Onigumo", component)
{:ok, module} = Map.fetch(@components, String.to_atom(component))
root_path = File.cwd!()
module.main(root_path)
end
Expand Down
2 changes: 1 addition & 1 deletion test/onigumo_cli_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule OnigumoCLITest do
end

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

test("run CLI with no arguments") do
Expand Down

0 comments on commit 4874162

Please sign in to comment.