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

Commitef221e8

Browse files
Nyholmfabpot
authored andcommitted
[Console] Make error message more verbose
1 parent176f52d commitef221e8

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