Skip to content

Commit

Permalink
fix: the remian args collect error
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jan 19, 2022
1 parent 96b4050 commit 6822123
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/Flags.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ public function bindingArguments(): self
continue;
}

// collect all remain args
if ($arg->isArray()) {
// collect all remain args
foreach ($args as $value) {
$arg->setValue($value);
}
Expand All @@ -387,13 +387,14 @@ public function bindingArguments(): self
}

if ($args) {
$args = array_values($args);

if ($this->strictMatchArgs) {
throw new FlagException(sprintf('unknown arguments (error: "%s").', implode(' ', $args)));
}

$this->remainArgs = array_values($args);
}

$this->remainArgs = $args;
return $this;
}

Expand Down
14 changes: 13 additions & 1 deletion src/FlagsParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ abstract class FlagsParser implements ParserInterface
protected array $flags = [];

/**
* The remaining raw args, after option parsed from {@see $flags}
* The raw args, after option parsed from {@see $flags}
*
* @var string[]
*/
Expand Down Expand Up @@ -495,6 +495,18 @@ public function popFirstRawArg(): string
return array_shift($this->rawArgs);
}

/**
* @return array
*/
public function getInfo(): array
{
return [
'flags' => $this->flags,
'rawArgs' => $this->rawArgs,
'remainArgs' => $this->remainArgs,
];
}

/**
* @return bool
*/
Expand Down
6 changes: 4 additions & 2 deletions src/SFlags.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,12 +572,14 @@ public function bindingArguments(): void
}

if ($args) {
$args = array_values($args);

if ($this->strictMatchArgs) {
throw new FlagException(sprintf('unknown arguments (error: "%s").', implode(', ', $args)));
}

$this->remainArgs = array_values($args);
}

$this->remainArgs = $args;
}

/**
Expand Down

0 comments on commit 6822123

Please sign in to comment.