Skip to content

Commit

Permalink
Just a example
Browse files Browse the repository at this point in the history
  • Loading branch information
nappex committed Jan 4, 2025
1 parent c0a743a commit 68fa8f9
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion lib/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,44 @@ defmodule Onigumo.CLI do
}

def main(argv) do
parsed = OptionParser.parse(argv, aliases: [C: :working_dir], strict: [working_dir: :string])
parsed =
OptionParser.parse(
argv,
aliases: [h: :help, C: :working_dir],
strict: [help: :boolean, 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
{[help: true], [], []} -> usage_message()
{_, _, [_ | _]} -> usage_message()
{_, argv, _} when length(argv) != 1 -> usage_message()
:error -> usage_message()
end

case parsed do
{[help: true], [], []} ->
usage_message()

{_, _, [_ | _]} ->
usage_message()

{_, argv, _} when length(argv) != 1 ->
usage_message()

{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
end
end

defp usage_message() do
Expand Down

0 comments on commit 68fa8f9

Please sign in to comment.