Skip to content

Commit

Permalink
TASK: Restructure --help evaluation
Browse files Browse the repository at this point in the history
- allows `flow --help`
- restricts that no command controller uses `$help` as custom option
- remove duplicate set `HelpCommandController`
- centralise $firstArgument "parsing"
- respect that $commandLine could be a string

Does not handle `flow cache:list --help=true` as this might be bungus
  • Loading branch information
mhsdesign committed Nov 4, 2024
1 parent 3d71e45 commit b9fc7ea
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions Neos.Flow/Classes/Cli/RequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,6 @@ public function build($commandLine): Request
$request = new Request();
$request->setControllerObjectName(HelpCommandController::class);

if (is_array($commandLine) && in_array('--help', $commandLine, true)) {
$request->setControllerCommandName('help');
$request->setArguments(['commandIdentifier' => $commandLine[0]]);
$request->setControllerObjectName(HelpCommandController::class);
return $request;
}

if (is_array($commandLine) === true) {
$rawCommandLineArguments = $commandLine;
} else {
Expand All @@ -147,14 +140,23 @@ public function build($commandLine): Request
}
}
}
if (count($rawCommandLineArguments) === 0) {
$firstArgument = count($rawCommandLineArguments) ? trim(array_shift($rawCommandLineArguments)) : null;
if (
$firstArgument === null
|| $firstArgument === '--help'
) {
$request->setControllerCommandName('helpStub');

return $request;
}
$commandIdentifier = trim(array_shift($rawCommandLineArguments));
if (in_array('--help', $rawCommandLineArguments, true)) {
$request->setControllerCommandName('help');
$request->setArguments(['commandIdentifier' => $firstArgument]);
return $request;
}

try {
$command = $this->commandManager->getCommandByIdentifier($commandIdentifier);
$command = $this->commandManager->getCommandByIdentifier($firstArgument);
} catch (CommandException $exception) {
$request->setArgument('exception', $exception);
$request->setControllerCommandName('error');
Expand Down Expand Up @@ -195,6 +197,9 @@ protected function parseRawCommandLineArguments(array $rawCommandLineArguments,
$requiredArguments = [];
$optionalArguments = [];
foreach ($commandMethodParameters as $parameterName => $parameterInfo) {
if ($parameterName === 'help') {
throw new \RuntimeException(sprintf('The option --help is reserved in %s::%s', $controllerObjectName, $commandMethodName), 1730715152);
}
if ($parameterInfo['optional'] === false) {
$requiredArguments[strtolower($parameterName)] = [
'parameterName' => $parameterName,
Expand Down

0 comments on commit b9fc7ea

Please sign in to comment.