Skip to content

Commit

Permalink
Replace with with case
Browse files Browse the repository at this point in the history
  • Loading branch information
Glutexo committed Jan 4, 2025
1 parent c0a743a commit 4348251
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions lib/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ defmodule Onigumo.CLI do
def main(argv) do
parsed = OptionParser.parse(argv, aliases: [C: :working_dir], strict: [working_dir: :string])

with {switches, [component], []} <- parsed,
{:ok, module} <- Map.fetch(@components, String.to_atom(component)) do
working_dir = Keyword.get(switches, :working_dir, File.cwd!())
module.main(working_dir)
else
{_, _, [_ | _]} -> usage_message()
{_, argv, _} when length(argv) != 1 -> usage_message()
:error -> usage_message()
case parsed do
{switches, [component], []} ->
case Map.fetch(@components, String.to_atom(component)) do
{:ok, module} ->
working_dir = Keyword.get(switches, :working_dir, File.cwd!())
module.main(working_dir)
:error ->
usage_message
end
{_, _, [_ | _]} ->
usage_message()
{_, argv, _} when length(argv) != 1 ->
usage_message()
end
end

Expand Down

0 comments on commit 4348251

Please sign in to comment.