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

Fix CommandParser incorrectly handling multiple end-of-option delimiters #3541

Merged
merged 4 commits into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions packages/cli/_test.pony
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ actor Main is TestList
test(_TestHelp)
test(_TestHelpFalse)
test(_TestHelpMultipleArgs)
test(_TestMultipleEndOfOptions)

class iso _TestMinimal is UnitTest
fun name(): String => "ponycli/minimal"
Expand Down Expand Up @@ -548,6 +549,25 @@ class iso _TestHelpMultipleArgs is UnitTest
h.assert_true(
help.contains("simple <words> <argz>"))

class iso _TestMultipleEndOfOptions is UnitTest
fun name(): String => "ponycli/multiple-end-of-options"

fun apply(h: TestHelper) ? =>
let cs = _Fixtures.corral_spec()?

let args: Array[String] = ["ignored"; "exec"; "--"; "lldb"; "ponyc"; "--"; "-v" ]
let cmdErr = CommandParser(cs).parse(args)
h.log("Parsed: " + cmdErr.string())

let cmd = cmdErr as Command
h.assert_eq[String]("corral/exec", cmd.fullname())

let argss = cmd.arg("args").string_seq()
h.assert_eq[String]("lldb", argss(0)?)
h.assert_eq[String]("ponyc", argss(1)?)
h.assert_eq[String]("--", argss(2)?)
h.assert_eq[String]("-v", argss(3)?)

primitive _Fixtures
fun bools_cli_spec(): CommandSpec box ? =>
"""
Expand Down Expand Up @@ -606,3 +626,24 @@ primitive _Fixtures
])?
])?
])?


fun corral_spec(): CommandSpec box ? =>
"""
A snippet from Corral's command spec to demonstrate multiple end of option arguments
"""
CommandSpec.parent("corral", "", [
OptionSpec.u64(
"debug",
"Configure debug output: 0=off, 1=err, 2=warn, 3=info, 4=fine."
where short'='g',
default' = 0)
], [
CommandSpec.leaf(
"exec",
"For executing shell commands which require user interaction",
Array[OptionSpec](),
[
ArgSpec.string_seq("args", "Arguments to run.")
])?
])?
2 changes: 1 addition & 1 deletion packages/cli/command_parser.pony
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CommandParser

while tokens.size() > 0 do
let token = try tokens.shift()? else "" end
if token == "--" then
if (token == "--") and (opt_stop == false) then
opt_stop = true

elseif not opt_stop and (token.compare_sub("--", 2, 0) == Equal) then
Expand Down