From 3d8bd1d975f8750ffe4ee01426c72c274d7bd113 Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 13 Apr 2023 19:48:42 +0800 Subject: [PATCH] It should add splitting extra argument to newArgv --- src/OptionParser.php | 6 +++++- tests/ContinuousOptionParserTest.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/OptionParser.php b/src/OptionParser.php index a3c11a4..efb7b74 100644 --- a/src/OptionParser.php +++ b/src/OptionParser.php @@ -98,7 +98,6 @@ protected function preprocessingArguments(array $argv) foreach ($argv as $arg) { if ($arg === '--') { $afterDash = true; - continue; } if ($afterDash) { $newArgv[] = $arg; @@ -175,6 +174,11 @@ public function parse(array $argv) } $spec = $this->specs->get($arg->getOptionName()); + + if ($arg->arg === '--') { + continue; + } + if (!$spec) { throw new InvalidOptionException('Invalid option: '.$arg); } diff --git a/tests/ContinuousOptionParserTest.php b/tests/ContinuousOptionParserTest.php index 2dbd93e..e0890bc 100644 --- a/tests/ContinuousOptionParserTest.php +++ b/tests/ContinuousOptionParserTest.php @@ -46,7 +46,7 @@ public function argumentProvider() ['program','-v', '-c', 'subcommand1', '--as', 99, 'arg1', 'arg2', 'arg3', '--','zz','xx','vv'], [ 'app' => ['verbose' => true], - 'args' => ['arg1', 'arg2', 'arg3', 'zz', 'xx', 'vv'] + 'args' => ['arg1', 'arg2', 'arg3', '--', 'zz', 'xx', 'vv'] ], ], ];