Skip to content

Commit ef221e8

Browse files
Nyholmfabpot
authored andcommitted
[Console] Make error message more verbose
1 parent 176f52d commit ef221e8

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-
throw new RuntimeException(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-
throw new RuntimeException(sprintf('No arguments expected, got "%s".', $token));
186+
throw new RuntimeException($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
new InputDefinition([new InputOption('foo', 'f', InputOption::VALUE_NONE)]),
248248
'The "-Щ" option does not exist.',
249249
],
250+
[
251+
['cli.php', 'acme:foo', 'bar'],
252+
new InputDefinition([new InputArgument('command', InputArgument::REQUIRED)]),
253+
'No arguments expected for "acme:foo" command, got "bar"',
254+
],
255+
[
256+
['cli.php', 'acme:foo', 'bar'],
257+
new InputDefinition([new InputArgument('name', InputArgument::REQUIRED)]),
258+
'Too many arguments, expected arguments "name".',
259+
],
250260
];
251261
}
252262

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy