Skip to content

Commit

Permalink
fix cli issue when providing --help=false.
Browse files Browse the repository at this point in the history
  • Loading branch information
mfelsche authored and SeanTAllen committed Jan 8, 2020
1 parent 764110c commit e1a6214
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
23 changes: 23 additions & 0 deletions packages/cli/_test.pony
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ actor Main is TestList
test(_TestChat)
test(_TestMustBeLeaf)
test(_TestHelp)
test(_TestHelpFalse)
test(_TestHelpMultipleArgs)

class iso _TestMinimal is UnitTest
Expand Down Expand Up @@ -514,6 +515,28 @@ class iso _TestHelp is UnitTest
h.log(help)
h.assert_true(help.contains("Address of the server"))

class iso _TestHelpFalse is UnitTest
fun name(): String => "ponycli/help-false"

fun apply(h: TestHelper) ? =>
let cs =
CommandSpec.leaf("bools", "A sample CLI with four bool options", [
OptionSpec.string("name" where short' = 'n', default' = "John")
])?.>add_help()?
let args = [
"ignored"
"--help=false"
]
let cmd = CommandParser(cs).parse(args)
match cmd
| let c: Command =>
h.assert_false(c.option("help").bool())
h.assert_eq[String]("John", c.option("name").string())
| let ch: CommandHelp => h.fail("--help=false is interpretet as demanding help output.")
| let se: SyntaxError =>
h.fail("--help=false is not handled correctly: " + se.string())
end

class iso _TestHelpMultipleArgs is UnitTest
fun name(): String => "ponycli/help-multiple-args"

Expand Down
17 changes: 10 additions & 7 deletions packages/cli/command_parser.pony
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,16 @@ class CommandParser
end

// If it's a help option, return a general or specific CommandHelp.
if options.contains(_help_name()) then
return
if _spec is _root_spec() then
Help.general(_root_spec())
else
Help.for_command(_root_spec(), [_spec.name()])
end
try
let help_option = options(_help_name())?
if help_option.bool() then
return
if _spec is _root_spec() then
Help.general(_root_spec())
else
Help.for_command(_root_spec(), [_spec.name()])
end
end
end

// If it's a help command, return a general or specific CommandHelp.
Expand Down

0 comments on commit e1a6214

Please sign in to comment.