Skip to content

Commit 6822123

Browse files
committed
fix: the remian args collect error
1 parent 96b4050 commit 6822123

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/Flags.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ public function bindingArguments(): self
374374
continue;
375375
}
376376

377+
// collect all remain args
377378
if ($arg->isArray()) {
378-
// collect all remain args
379379
foreach ($args as $value) {
380380
$arg->setValue($value);
381381
}
@@ -387,13 +387,14 @@ public function bindingArguments(): self
387387
}
388388

389389
if ($args) {
390+
$args = array_values($args);
391+
390392
if ($this->strictMatchArgs) {
391393
throw new FlagException(sprintf('unknown arguments (error: "%s").', implode(' ', $args)));
392394
}
393-
394-
$this->remainArgs = array_values($args);
395395
}
396396

397+
$this->remainArgs = $args;
397398
return $this;
398399
}
399400

src/FlagsParser.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ abstract class FlagsParser implements ParserInterface
102102
protected array $flags = [];
103103

104104
/**
105-
* The remaining raw args, after option parsed from {@see $flags}
105+
* The raw args, after option parsed from {@see $flags}
106106
*
107107
* @var string[]
108108
*/
@@ -495,6 +495,18 @@ public function popFirstRawArg(): string
495495
return array_shift($this->rawArgs);
496496
}
497497

498+
/**
499+
* @return array
500+
*/
501+
public function getInfo(): array
502+
{
503+
return [
504+
'flags' => $this->flags,
505+
'rawArgs' => $this->rawArgs,
506+
'remainArgs' => $this->remainArgs,
507+
];
508+
}
509+
498510
/**
499511
* @return bool
500512
*/

src/SFlags.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -572,12 +572,14 @@ public function bindingArguments(): void
572572
}
573573

574574
if ($args) {
575+
$args = array_values($args);
576+
575577
if ($this->strictMatchArgs) {
576578
throw new FlagException(sprintf('unknown arguments (error: "%s").', implode(', ', $args)));
577579
}
578-
579-
$this->remainArgs = array_values($args);
580580
}
581+
582+
$this->remainArgs = $args;
581583
}
582584

583585
/**

0 commit comments

Comments
 (0)