Skip to content

Commit

Permalink
Allow commands to have hidden aliases; add BC for environment:backup
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcdawkins committed Sep 4, 2015
1 parent dad06dd commit 039dac0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 9 deletions.
28 changes: 28 additions & 0 deletions src/Command/PlatformCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ abstract class PlatformCommand extends Command
protected $environmentsTtl;

private $hiddenInList = false;
private $hiddenAliases = array();

/**
* The project, selected either by an option or the CWD.
Expand Down Expand Up @@ -865,4 +866,31 @@ protected function runOtherCommand($name, array $arguments = array(), InputInter

return $command->run($cmdInput, $this->output);
}

/**
* Add aliases that should be hidden from help.
*
* @see parent::setAliases()
*
* @param array $hiddenAliases
*
* @return self
*/
protected function setHiddenAliases(array $hiddenAliases)
{
$this->hiddenAliases = $hiddenAliases;
$this->setAliases(array_merge($this->getAliases(), $hiddenAliases));

return $this;
}

/**
* Get aliases that should be visible in help.
*
* @return array
*/
public function getVisibleAliases()
{
return array_diff($this->getAliases(), $this->hiddenAliases);
}
}
1 change: 1 addition & 0 deletions src/Command/Snapshot/SnapshotCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ protected function configure()
{
$this
->setName('snapshot:create')
->setHiddenAliases(array('backup', 'environment:backup'))
->setDescription('Make a snapshot of an environment')
->addArgument('environment', InputArgument::OPTIONAL, 'The environment')
->addOption('no-wait', null, InputOption::VALUE_NONE, 'Do not wait for the snapshot to complete');
Expand Down
1 change: 1 addition & 0 deletions src/Command/Snapshot/SnapshotRestoreCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ protected function configure()
{
$this
->setName('snapshot:restore')
->setHiddenAliases(array('environment:restore'))
->setDescription('Restore an environment snapshot')
->addArgument('snapshot', InputArgument::OPTIONAL, 'The name of the snapshot. Defaults to the most recent one')
->addOption('no-wait', null, InputOption::VALUE_NONE, 'Do not wait for the operation to complete');
Expand Down
5 changes: 3 additions & 2 deletions src/Console/CustomMarkdownDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ protected function describeCommand(Command $command, array $options = array())
$this->write("$description\n\n");
}

if ($command->getAliases()) {
$aliases = $command instanceof PlatformCommand ? $command->getVisibleAliases() : $command->getAliases();
if ($aliases) {
$this->write(
'Aliases: ' . '`'.implode('`, `', $command->getAliases()).'`' . "\n\n"
'Aliases: ' . '`'.implode('`, `', $aliases).'`' . "\n\n"
);
}

Expand Down
18 changes: 11 additions & 7 deletions src/Console/CustomTextDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ protected function describeCommand(Command $command, array $options = array())
$command->mergeApplicationDefinition(false);

$this->writeText("<comment>Command:</comment> " . $command->getName(), $options);
if ($aliases = $command->getAliases()) {

$aliases = $command instanceof PlatformCommand ? $command->getVisibleAliases() : $command->getAliases();
if ($aliases) {
$this->writeText("\n");
$this->writeText('<comment>Aliases:</comment> ' . implode(', ', $aliases), $options);
}

if ($description = $command->getDescription()) {
$this->writeText("\n");
$this->writeText("<comment>Description:</comment> $description", $options);
Expand Down Expand Up @@ -103,16 +106,17 @@ protected function describeApplication(ConsoleApplication $application, array $o
foreach ($namespace['commands'] as $name) {
$command = $description->getCommand($name);
$aliases = $command->getAliases();
if ($aliases && ApplicationDescription::GLOBAL_NAMESPACE === $namespace['id'] && in_array(
$name,
$aliases
)
) {
// If the command has aliases, do not list it in the
if ($aliases && in_array($name, $aliases)) {
// If the command is an alias, do not list it in the
// 'global' namespace. The aliases will be shown inline
// with the full command name.
continue;
}

if ($command instanceof PlatformCommand) {
$aliases = $command->getVisibleAliases();
}

// Colour local commands differently from remote ones.
$commandDescription = $command->getDescription();
if ($command instanceof PlatformCommand && !$command->isLocal()) {
Expand Down

0 comments on commit 039dac0

Please sign in to comment.