feature #38919 [Console] Make error message more verbose (Nyholm)
This PR was squashed before being merged into the 5.2-dev branch.
Discussion
----------
[Console] Make error message more verbose
| Q | A
| ------------- | ---
| Branch? | 5.x
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| Tickets | Fix #38904
| License | MIT
| Doc PR | no
This will make the error message a bit more verbose when you are using too many or too few arguments.
Commits
-------
ef221e88aa
[Console] Make error message more verbose
This commit is contained in:
commit
f5bd922e5b
@ -165,11 +165,25 @@ class ArgvInput extends Input
|
|||||||
// unexpected argument
|
// unexpected argument
|
||||||
} else {
|
} else {
|
||||||
$all = $this->definition->getArguments();
|
$all = $this->definition->getArguments();
|
||||||
if (\count($all)) {
|
$symfonyCommandName = null;
|
||||||
throw new RuntimeException(sprintf('Too many arguments, expected arguments "%s".', implode('" "', array_keys($all))));
|
if (($inputArgument = $all[$key = array_key_first($all)] ?? null) && 'command' === $inputArgument->getName()) {
|
||||||
|
$symfonyCommandName = $this->arguments['command'] ?? null;
|
||||||
|
unset($all[$key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new RuntimeException(sprintf('No arguments expected, got "%s".', $token));
|
if (\count($all)) {
|
||||||
|
if ($symfonyCommandName) {
|
||||||
|
$message = sprintf('Too many arguments to "%s" command, expected arguments "%s".', $symfonyCommandName, implode('" "', array_keys($all)));
|
||||||
|
} else {
|
||||||
|
$message = sprintf('Too many arguments, expected arguments "%s".', implode('" "', array_keys($all)));
|
||||||
|
}
|
||||||
|
} elseif ($symfonyCommandName) {
|
||||||
|
$message = sprintf('No arguments expected for "%s" command, got "%s".', $symfonyCommandName, $token);
|
||||||
|
} else {
|
||||||
|
$message = sprintf('No arguments expected, got "%s".', $token);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new RuntimeException($message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,6 +247,16 @@ class ArgvInputTest extends TestCase
|
|||||||
new InputDefinition([new InputOption('foo', 'f', InputOption::VALUE_NONE)]),
|
new InputDefinition([new InputOption('foo', 'f', InputOption::VALUE_NONE)]),
|
||||||
'The "-Щ" option does not exist.',
|
'The "-Щ" option does not exist.',
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
['cli.php', 'acme:foo', 'bar'],
|
||||||
|
new InputDefinition([new InputArgument('command', InputArgument::REQUIRED)]),
|
||||||
|
'No arguments expected for "acme:foo" command, got "bar"',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
['cli.php', 'acme:foo', 'bar'],
|
||||||
|
new InputDefinition([new InputArgument('name', InputArgument::REQUIRED)]),
|
||||||
|
'Too many arguments, expected arguments "name".',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user