Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature to conditionally hide commands #1037

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,34 @@ public function registerCommandClass($app, $commandClass)
$container = Robo::getContainer();
$roboCommandFileInstance = $this->instantiateCommandClass($commandClass);
if (!$roboCommandFileInstance) {
return;
return null;
}

// Register commands for all of the public methods in the RoboFile.
$commandFactory = $container->get('commandFactory');
$commandList = $commandFactory->createCommandsFromClass($roboCommandFileInstance);

// Get all of the hidden commands if there is a $hiddenCommands property in $roboCommandFileInstance
$hiddenCommands = $roboCommandFileInstance->hiddenCommands ?? [];
// If $hiddenCommands is a string then convert it to an array
if (is_string($hiddenCommands)) {
$hiddenCommands = [$hiddenCommands];
}
// If $hiddenCommands isn't an array at this point then make it an empty array
if (!is_array($hiddenCommands)) {
$hiddenCommands = [];
}

foreach ($commandList as $command) {
// If the command is in the $hiddenCommands array then don't add the command
if (in_array($command->getName(), $hiddenCommands)) {
continue;
}
// If the command has a @hidden annotation then don't add the command
$annotations = $command->getAnnotationData();
if ($annotations && $annotations->has('hidden')) {
continue;
}
$app->add($command);
}
return $roboCommandFileInstance;
Expand Down