Skip to content

Commit 064b748

Browse files
CLI-1731: ACLI documentation expose MEO commands that should be hidden (#1970)
* CLI-1731: ACLI documentation expose MEO commands that should be hidden * CLI-1731: ACLI documentation expose MEO commands that should be hidden * CLI-1731: ACLI documentation expose MEO commands that should be hidden * CLI-1731: Ide commands removed from hidden flag while make docs * CLI-1731: Ide commands removed from hidden flag while make docs * CLI-1731: Ide commands helper text * CLI-1731: Ide commands helper text mutation solved * CLI-1731: Ide commands helper text mutation solved * CLI-1731: As per danes suggestion changed logic for namespaceHasVisibleCommand
1 parent 747540a commit 064b748

21 files changed

+292
-3
lines changed

src/Command/Api/ApiCommandHelper.php

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,10 +532,11 @@ private function generateApiListCommands(array $apiCommands, string $commandPref
532532
continue;
533533
}
534534
$namespace = $commandNameParts[1];
535-
if (!array_key_exists($namespace, $apiListCommands)) {
535+
$name = $commandPrefix . ':' . $namespace;
536+
$hasVisibleCommand = $this->namespaceHasVisibleCommand($apiCommands, $namespace);
537+
if (!array_key_exists($name, $apiListCommands) && $hasVisibleCommand) {
536538
/** @var \Acquia\Cli\Command\Acsf\AcsfListCommand|\Acquia\Cli\Command\Api\ApiListCommand $command */
537539
$command = $commandFactory->createListCommand();
538-
$name = $commandPrefix . ':' . $namespace;
539540
$command->setName($name);
540541
$command->setNamespace($name);
541542
$command->setAliases([]);
@@ -546,6 +547,42 @@ private function generateApiListCommands(array $apiCommands, string $commandPref
546547
return $apiListCommands;
547548
}
548549

550+
/**
551+
* Whether any API command in the given namespace is visible (not hidden).
552+
*
553+
* List commands (api:{namespace}) are only registered when at least one sub-command
554+
* under that namespace exists and is visible. If every sub-command is hidden
555+
* (deprecated/pre-release), the namespace list is omitted.
556+
*
557+
* @param ApiBaseCommand[] $apiCommands
558+
*/
559+
private function namespaceHasVisibleCommand(array $apiCommands, string $namespace): bool
560+
{
561+
$commandsInNamespace = [];
562+
foreach ($apiCommands as $apiCommand) {
563+
$commandNameParts = explode(':', $apiCommand->getName());
564+
if (count($commandNameParts) < 3) {
565+
continue;
566+
}
567+
if ($commandNameParts[1] !== $namespace) {
568+
continue;
569+
}
570+
$commandsInNamespace[] = $apiCommand;
571+
}
572+
573+
if ($commandsInNamespace === []) {
574+
return false;
575+
}
576+
577+
foreach ($commandsInNamespace as $command) {
578+
if (!$command->isHidden()) {
579+
return true;
580+
}
581+
}
582+
583+
return false;
584+
}
585+
549586
/**
550587
* @param array<mixed> $requestBody
551588
* @return array<mixed>

src/Command/CommandBase.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ public function appendHelp(string $helpText): void
152152
$this->setHelp($helpText);
153153
}
154154

155+
/**
156+
* Helper text for IDE-only commands.
157+
*/
158+
public static function getIdeHelperText(): string
159+
{
160+
return 'This command will only work in an IDE terminal.';
161+
}
162+
155163
protected static function getUuidRegexConstraint(): Regex
156164
{
157165
return new Regex([

src/Command/Ide/IdePhpVersionCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Acquia\Cli\Command\Ide;
66

7+
use Acquia\Cli\Command\CommandBase;
78
use Acquia\Cli\Exception\AcquiaCliException;
89
use Acquia\DrupalEnvironmentDetector\AcquiaDrupalEnvironmentDetector;
910
use Symfony\Component\Console\Attribute\AsCommand;
@@ -22,6 +23,7 @@ protected function configure(): void
2223
$this
2324
->addArgument('version', InputArgument::REQUIRED, 'The PHP version')
2425
->setHidden(!AcquiaDrupalEnvironmentDetector::isAhIdeEnv());
26+
$this->appendHelp(CommandBase::getIdeHelperText());
2527
}
2628

2729
protected function execute(InputInterface $input, OutputInterface $output): int

src/Command/Ide/IdeServiceRestartCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Acquia\Cli\Command\Ide;
66

7+
use Acquia\Cli\Command\CommandBase;
78
use Acquia\DrupalEnvironmentDetector\AcquiaDrupalEnvironmentDetector;
89
use Symfony\Component\Console\Attribute\AsCommand;
910
use Symfony\Component\Console\Command\Command;
@@ -25,6 +26,7 @@ protected function configure(): void
2526
->addUsage('apache')
2627
->addUsage('mysql')
2728
->setHidden(!AcquiaDrupalEnvironmentDetector::isAhIdeEnv());
29+
$this->appendHelp(CommandBase::getIdeHelperText());
2830
}
2931

3032
protected function execute(InputInterface $input, OutputInterface $output): int

src/Command/Ide/IdeServiceStartCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Acquia\Cli\Command\Ide;
66

7+
use Acquia\Cli\Command\CommandBase;
78
use Acquia\DrupalEnvironmentDetector\AcquiaDrupalEnvironmentDetector;
89
use Symfony\Component\Console\Attribute\AsCommand;
910
use Symfony\Component\Console\Command\Command;
@@ -25,6 +26,7 @@ protected function configure(): void
2526
->addUsage('apache')
2627
->addUsage('mysql')
2728
->setHidden(!AcquiaDrupalEnvironmentDetector::isAhIdeEnv());
29+
$this->appendHelp(CommandBase::getIdeHelperText());
2830
}
2931

3032
protected function execute(InputInterface $input, OutputInterface $output): int

src/Command/Ide/IdeServiceStopCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Acquia\Cli\Command\Ide;
66

7+
use Acquia\Cli\Command\CommandBase;
78
use Acquia\DrupalEnvironmentDetector\AcquiaDrupalEnvironmentDetector;
89
use Symfony\Component\Console\Attribute\AsCommand;
910
use Symfony\Component\Console\Command\Command;
@@ -25,6 +26,7 @@ protected function configure(): void
2526
->addUsage('apache')
2627
->addUsage('mysql')
2728
->setHidden(!AcquiaDrupalEnvironmentDetector::isAhIdeEnv());
29+
$this->appendHelp(CommandBase::getIdeHelperText());
2830
}
2931

3032
protected function execute(InputInterface $input, OutputInterface $output): int

src/Command/Ide/IdeShareCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ protected function configure(): void
2626
$this
2727
->addOption('regenerate', '', InputOption::VALUE_NONE, 'regenerate the share code')
2828
->setHidden(!AcquiaDrupalEnvironmentDetector::isAhIdeEnv());
29+
$this->appendHelp(CommandBase::getIdeHelperText());
2930
}
3031

3132
protected function execute(InputInterface $input, OutputInterface $output): int

src/Command/Ide/IdeXdebugToggleCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Acquia\Cli\Command\Ide;
66

7+
use Acquia\Cli\Command\CommandBase;
78
use Acquia\Cli\Exception\AcquiaCliException;
89
use Acquia\DrupalEnvironmentDetector\AcquiaDrupalEnvironmentDetector;
910
use Symfony\Component\Console\Attribute\AsCommand;
@@ -20,6 +21,7 @@ protected function configure(): void
2021
{
2122
$this
2223
->setHidden(!AcquiaDrupalEnvironmentDetector::isAhIdeEnv());
24+
$this->appendHelp(CommandBase::getIdeHelperText());
2325
}
2426

2527
protected function execute(InputInterface $input, OutputInterface $output): int

src/Command/Ide/Wizard/IdeWizardCreateSshKeyCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ protected function configure(): void
2121
{
2222
$this
2323
->setHidden(!CommandBase::isAcquiaCloudIde());
24+
$this->appendHelp(CommandBase::getIdeHelperText());
2425
}
2526

2627
protected function execute(InputInterface $input, OutputInterface $output): int

src/Command/Ide/Wizard/IdeWizardDeleteSshKeyCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ protected function configure(): void
2323
{
2424
$this
2525
->setHidden(!CommandBase::isAcquiaCloudIde());
26+
$this->appendHelp(CommandBase::getIdeHelperText());
2627
}
2728

2829
protected function execute(InputInterface $input, OutputInterface $output): int

0 commit comments

Comments
 (0)