Skip to content

Commit

Permalink
Use case instead of MatchErrror
Browse files Browse the repository at this point in the history
Instead of pattern matching causing a MatchError, use case directly
matching pattern for the happy path and for the invalid argument path.
  • Loading branch information
Glutexo committed Feb 24, 2024
1 parent d6394fc commit 445b867
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions lib/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ defmodule Onigumo.CLI do
}

def main(argv) do
try do
{[], argv, []} = OptionParser.parse(argv, strict: [])
argv
rescue
MatchError -> usage_message()
else
[component] ->
case OptionParser.parse(argv, strict: []) do
{[], [component], []} ->
{:ok, module} = Map.fetch(@components, String.to_atom(component))
root_path = File.cwd!()
module.main(root_path)

_ ->
usage_message()
end
Expand Down

0 comments on commit 445b867

Please sign in to comment.