Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf5bd922

Browse files
committed
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 | noThis will make the error message a bit more verbose when you are using too many or too few arguments.Commits-------ef221e8 [Console] Make error message more verbose
2 parents8bac7a0 +ef221e8 commitf5bd922

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

‎src/Symfony/Component/Console/Input/ArgvInput.php‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,25 @@ private function parseArgument(string $token)
165165
// unexpected argument
166166
}else {
167167
$all =$this->definition->getArguments();
168+
$symfonyCommandName =null;
169+
if (($inputArgument =$all[$key =array_key_first($all)] ??null) &&'command' ===$inputArgument->getName()) {
170+
$symfonyCommandName =$this->arguments['command'] ??null;
171+
unset($all[$key]);
172+
}
173+
168174
if (\count($all)) {
169-
thrownewRuntimeException(sprintf('Too many arguments, expected arguments "%s".',implode('" "',array_keys($all))));
175+
if ($symfonyCommandName) {
176+
$message =sprintf('Too many arguments to "%s" command, expected arguments "%s".',$symfonyCommandName,implode('" "',array_keys($all)));
177+
}else {
178+
$message =sprintf('Too many arguments, expected arguments "%s".',implode('" "',array_keys($all)));
179+
}
180+
}elseif ($symfonyCommandName) {
181+
$message =sprintf('No arguments expected for "%s" command, got "%s".',$symfonyCommandName,$token);
182+
}else {
183+
$message =sprintf('No arguments expected, got "%s".',$token);
170184
}
171185

172-
thrownewRuntimeException(sprintf('No arguments expected, got "%s".',$token));
186+
thrownewRuntimeException($message);
173187
}
174188
}
175189

‎src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,16 @@ public function provideInvalidInput()
247247
newInputDefinition([newInputOption('foo','f', InputOption::VALUE_NONE)]),
248248
'The "-Щ" option does not exist.',
249249
],
250+
[
251+
['cli.php','acme:foo','bar'],
252+
newInputDefinition([newInputArgument('command', InputArgument::REQUIRED)]),
253+
'No arguments expected for "acme:foo" command, got "bar"',
254+
],
255+
[
256+
['cli.php','acme:foo','bar'],
257+
newInputDefinition([newInputArgument('name', InputArgument::REQUIRED)]),
258+
'Too many arguments, expected arguments "name".',
259+
],
250260
];
251261
}
252262

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp