[Console] Make error message more verbose
This commit is contained in:
parent
176f52d630
commit
ef221e88aa
@ -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