From 9ab2aab849d343ae46958eca53d09ae848592358 Mon Sep 17 00:00:00 2001 From: Rocco Bowling Date: Wed, 6 May 2020 17:27:37 -0400 Subject: [PATCH 1/3] Stop swallowing "--" after the first one is processed by command parser Previously, the command parser would swallow all "--" after the first one. For me, this manifested itself in not allowing corral to be used with lldb "corral exec -- lldb ponyc -- $(ponyc) -V=0 -o ./build/ ./utility" since the second "--" is required to be passed to lldb. This change is dependency for a PR being submitted to corral to allow use of corral with lldb (for debugging ponyc itself). --- packages/cli/command_parser.pony | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/command_parser.pony b/packages/cli/command_parser.pony index fff33ccdfb..92d7023bfd 100644 --- a/packages/cli/command_parser.pony +++ b/packages/cli/command_parser.pony @@ -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 From fca721700c56885e3565db9d51459934a4ae5321 Mon Sep 17 00:00:00 2001 From: Rocco Bowling Date: Wed, 6 May 2020 20:29:02 -0400 Subject: [PATCH 2/3] adding test for multiple end-of-options issue --- packages/cli/_test.pony | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/packages/cli/_test.pony b/packages/cli/_test.pony index c4ca02f7ca..8218734877 100644 --- a/packages/cli/_test.pony +++ b/packages/cli/_test.pony @@ -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" @@ -548,6 +549,25 @@ class iso _TestHelpMultipleArgs is UnitTest h.assert_true( help.contains("simple ")) +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 ? => """ @@ -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.") + ])? + ])? From f4b437465bc93274536648525f53b343dd495aa4 Mon Sep 17 00:00:00 2001 From: Rocco Bowling Date: Wed, 6 May 2020 17:27:37 -0400 Subject: [PATCH 3/3] adding test for multiple end-of-options issue (+1 squashed commit) Squashed commits: [9ab2aab8] Stop swallowing "--" after the first one is processed by command parser Previously, the command parser would swallow all "--" after the first one. For me, this manifested itself in not allowing corral to be used with lldb "corral exec -- lldb ponyc -- $(ponyc) -V=0 -o ./build/ ./utility" since the second "--" is required to be passed to lldb. This change is dependency for a PR being submitted to corral to allow use of corral with lldb (for debugging ponyc itself). --- packages/cli/_test.pony | 41 ++++++++++++++++++++++++++++++++ packages/cli/command_parser.pony | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/packages/cli/_test.pony b/packages/cli/_test.pony index c4ca02f7ca..8218734877 100644 --- a/packages/cli/_test.pony +++ b/packages/cli/_test.pony @@ -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" @@ -548,6 +549,25 @@ class iso _TestHelpMultipleArgs is UnitTest h.assert_true( help.contains("simple ")) +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 ? => """ @@ -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.") + ])? + ])? diff --git a/packages/cli/command_parser.pony b/packages/cli/command_parser.pony index fff33ccdfb..92d7023bfd 100644 --- a/packages/cli/command_parser.pony +++ b/packages/cli/command_parser.pony @@ -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