Fix ConsoleApplication parsing
This commit is contained in:
@@ -13,13 +13,30 @@ final class ConsoleApplication
|
|||||||
|
|
||||||
public function run(array $argv): int
|
public function run(array $argv): int
|
||||||
{
|
{
|
||||||
$commandStr = $argv[1] ?? null;
|
if (!isset($argv[1]) || $argv[1] === 'help') {
|
||||||
|
|
||||||
if ($commandStr === null || $commandStr === 'help') {
|
|
||||||
$this->printHelp($argv[2] ?? null);
|
$this->printHelp($argv[2] ?? null);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Split argv (after script name) into positional command tokens and option tokens.
|
||||||
|
// Positional tokens form the command string matched against command signatures
|
||||||
|
// (e.g. "users:create admin"). Tokens from the first "--" onwards are options.
|
||||||
|
$positional = [];
|
||||||
|
$optionTokens = [];
|
||||||
|
$inOptions = false;
|
||||||
|
for ($i = 1, $n = count($argv); $i < $n; $i++) {
|
||||||
|
$tok = $argv[$i];
|
||||||
|
if (!$inOptions && str_starts_with($tok, '--')) {
|
||||||
|
$inOptions = true;
|
||||||
|
}
|
||||||
|
if ($inOptions) {
|
||||||
|
$optionTokens[] = $tok;
|
||||||
|
} else {
|
||||||
|
$positional[] = $tok;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$commandStr = implode(' ', $positional);
|
||||||
$match = $this->router->match($commandStr);
|
$match = $this->router->match($commandStr);
|
||||||
|
|
||||||
if (!$match->found) {
|
if (!$match->found) {
|
||||||
@@ -31,7 +48,7 @@ final class ConsoleApplication
|
|||||||
$input = ConsoleInput::parse(
|
$input = ConsoleInput::parse(
|
||||||
$commandStr,
|
$commandStr,
|
||||||
$match->pathParams,
|
$match->pathParams,
|
||||||
array_slice($argv, 2),
|
$optionTokens,
|
||||||
$match->definition->options,
|
$match->definition->options,
|
||||||
);
|
);
|
||||||
$output = new ConsoleOutput();
|
$output = new ConsoleOutput();
|
||||||
|
|||||||
Reference in New Issue
Block a user