Skip to content

Commit

Permalink
Merge pull request #249 from Glutexo/with-module
Browse files Browse the repository at this point in the history
Help message on invalid component
  • Loading branch information
nappex authored Nov 9, 2024
2 parents fcfea46 + 6811b1a commit ded9aa9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions lib/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ defmodule Onigumo.CLI do
strict: [working_dir: :string]
) do
{switches, [component], []} ->
{:ok, module} = Map.fetch(@components, String.to_atom(component))
working_dir = Keyword.get(switches, :working_dir, File.cwd!())
module.main(working_dir)
with {:ok, module} <- Map.fetch(@components, String.to_atom(component)) do
working_dir = Keyword.get(switches, :working_dir, File.cwd!())
module.main(working_dir)
else
:error -> usage_message()
end

_ ->
usage_message()
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 @@ -21,7 +21,7 @@ defmodule OnigumoCLITest do
describe("Onigumo.CLI.main/1") do
for argument <- @invalid_arguments do
test("run CLI with invalid argument #{inspect(argument)}") do
assert_raise(MatchError, fn -> Onigumo.CLI.main([unquote(argument)]) end)
assert usage_message_printed?(fn -> Onigumo.CLI.main([unquote(argument)]) end)
end
end

Expand Down

0 comments on commit ded9aa9

Please sign in to comment.