Skip to content

Commit

Permalink
Fix dynamic disabling of lazy-loaded commands
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcdawkins committed Dec 5, 2024
1 parent e123f1c commit 60afea4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ protected function configureIO(InputInterface $input, OutputInterface $output):
*/
protected function doRunCommand(ConsoleCommand $command, InputInterface $input, OutputInterface $output): int
{
if (!$command->isEnabled()) {
throw new \InvalidArgumentException(sprintf('The command "%s" is not enabled.', $command->getName()));
}

if ($command instanceof MultiAwareInterface) {
$command->setRunningViaMulti($this->runningViaMulti);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Console/CustomMarkdownDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function describeApplication(Application $application, array $options
if ($command instanceof LazyCommand) {
$command = $command->getCommand();
}
if ($command->isHidden()) {
if ($command->isHidden() || !$command->isEnabled()) {
unset($namespace['commands'][$key]);
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Console/CustomTextDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected function describeApplication(ConsoleApplication $application, array $o
}

// Ensure the command is only shown under its canonical name.
if ($name === $command->getName() && !$command->isHidden()) {
if ($name === $command->getName() && !$command->isHidden() && $command->isEnabled()) {
$commands[$name] = $command;
}
}
Expand Down

0 comments on commit 60afea4

Please sign in to comment.