Skip to content

Commit

Permalink
feature #20029 Hide commands from ApplicationDescriptor, but allow in…
Browse files Browse the repository at this point in the history
…voking (jwdeitch, Jordan Deitch)

This PR was merged into the 3.2-dev branch.

Discussion
----------

Hide commands from ApplicationDescriptor, but allow invoking

I would like to hide commands from cluttering the descriptors, but still allow their invocation from code or cron.

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | comma-separated list of tickets fixed by the PR, if any
| License       | MIT
| Doc PR        | reference to the documentation PR, if any

Commits
-------

746dab3 casting setPublic() arg to bool
0a3c290 update docblocks and added test
6d87837 Update ApplicationDescription.php
e969581 update hidden to public
3efa874 Update Command.php
dfc1ac8 Update Command.php
cd77139 Update Command.php
56a8b93 Update Command.php
fb1f30c Update Command.php
1993196 Update Command.php
1add2ad Update Command.php
b73f494 Update ApplicationDescription.php
8d0262f Update Command.php
b423ab4 Add hidden field
  • Loading branch information
fabpot committed Oct 5, 2016
2 parents 5e63ad0 + 746dab3 commit 043ccd5
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/Symfony/Component/Console/Command/Command.php
Expand Up @@ -34,6 +34,7 @@ class Command
private $processTitle;
private $aliases = array();
private $definition;
private $public = true;
private $help;
private $description;
private $ignoreValidationErrors = false;
Expand Down Expand Up @@ -446,6 +447,26 @@ public function getName()
return $this->name;
}

/**
* @param bool $public Whether the command should be publicly shown or not.
*
* @return Command The current instance
*/
public function setPublic($public)
{
$this->public = (bool) $public;

return $this;
}

/**
* @return bool Whether the command should be publicly shown or not.
*/
public function isPublic()
{
return $this->public;
}

/**
* Sets the description for the command.
*
Expand Down
Expand Up @@ -112,7 +112,7 @@ private function inspectApplication()

/** @var Command $command */
foreach ($commands as $name => $command) {
if (!$command->getName()) {
if (!$command->getName() || !$command->isPublic()) {
continue;
}

Expand Down
Expand Up @@ -20,5 +20,6 @@ public function __construct()
parent::__construct('My Symfony application', 'v1.0');
$this->add(new DescriptorCommand1());
$this->add(new DescriptorCommand2());
$this->add(new DescriptorCommand3());
}
}
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Console\Tests\Fixtures;

use Symfony\Component\Console\Command\Command;

class DescriptorCommand3 extends Command
{
protected function configure()
{
$this
->setName('descriptor:command3')
->setDescription('command 3 description')
->setHelp('command 3 help')
->setPublic(false)
;
}
}

0 comments on commit 043ccd5

Please sign in to comment.