diff --git a/src/Symfony/Component/Console/Command/Command.php b/src/Symfony/Component/Console/Command/Command.php index 0d5001bb187a..8649756e87d8 100644 --- a/src/Symfony/Component/Console/Command/Command.php +++ b/src/Symfony/Component/Console/Command/Command.php @@ -34,6 +34,7 @@ class Command private $processTitle; private $aliases = array(); private $definition; + private $public = true; private $help; private $description; private $ignoreValidationErrors = false; @@ -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. * diff --git a/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php b/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php index 89961b9cae7d..49040d2d2064 100644 --- a/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php +++ b/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php @@ -112,7 +112,7 @@ private function inspectApplication() /** @var Command $command */ foreach ($commands as $name => $command) { - if (!$command->getName()) { + if (!$command->getName() || !$command->isPublic()) { continue; } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplication2.php b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplication2.php index ff5513580041..0fe87a18e436 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplication2.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplication2.php @@ -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()); } } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand3.php b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand3.php new file mode 100644 index 000000000000..f375778ce3c0 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand3.php @@ -0,0 +1,27 @@ + + * + * 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) + ; + } +}