Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement switch -h, --help to CLI #238

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
8 changes: 6 additions & 2 deletions lib/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ defmodule Onigumo.CLI do
def main(argv) do
case OptionParser.parse(
argv,
aliases: [C: :working_dir],
strict: [working_dir: :string]
aliases: [h: :help, C: :working_dir],
strict: [help: :boolean, working_dir: :string]
) do
{[help: true], [], []} ->
usage_message()

{parsed_switches, [component], []} ->
{:ok, module} = Map.fetch(@components, String.to_atom(component))
working_dir = Keyword.get(parsed_switches, :working_dir, File.cwd!())
Expand All @@ -30,6 +33,7 @@ defmodule Onigumo.CLI do
COMPONENT\tOnigumo component to run, available: #{components}

OPTIONS:
-h, --help\t\tusage help
nappex marked this conversation as resolved.
Show resolved Hide resolved
-C, --working-dir <dir>\tChange working dir to <dir> before running
""")
end
Expand Down
6 changes: 6 additions & 0 deletions test/onigumo_cli_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ defmodule OnigumoCLITest do
end
end

for switch <- ["-h", "--help", "--help -C prdel", "-h --invalid-switch"] do
nappex marked this conversation as resolved.
Show resolved Hide resolved
nappex marked this conversation as resolved.
Show resolved Hide resolved
test("run CLI with #{inspect(switch)} switch(es)") do
assert usage_message_printed?(fn -> Onigumo.CLI.main([unquote(switch)]) end)
end
end

defp usage_message_printed?(function) do
output = capture_io(function)
String.starts_with?(output, "Usage: onigumo ")
Expand Down
Loading