From da67c121d314186f05d0c1e5c58b4f0a33393f65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Fri, 22 Mar 2013 14:40:47 +0100 Subject: [PATCH 01/24] [Console] added descriptor & refactored description commands --- .../Command/AbstractDescriptorCommand.php | 45 ++++++++++ .../Component/Console/Command/HelpCommand.php | 24 ++--- .../Component/Console/Command/ListCommand.php | 31 +++---- .../Descriptor/DescriptorInterface.php | 51 +++++++++++ .../Console/Descriptor/DescriptorProvider.php | 89 +++++++++++++++++++ .../Console/Helper/DescriptorHelper.php | 54 +++++++++++ 6 files changed, 265 insertions(+), 29 deletions(-) create mode 100644 src/Symfony/Component/Console/Command/AbstractDescriptorCommand.php create mode 100644 src/Symfony/Component/Console/Descriptor/DescriptorInterface.php create mode 100644 src/Symfony/Component/Console/Descriptor/DescriptorProvider.php create mode 100644 src/Symfony/Component/Console/Helper/DescriptorHelper.php diff --git a/src/Symfony/Component/Console/Command/AbstractDescriptorCommand.php b/src/Symfony/Component/Console/Command/AbstractDescriptorCommand.php new file mode 100644 index 0000000000000..3564b84e02d33 --- /dev/null +++ b/src/Symfony/Component/Console/Command/AbstractDescriptorCommand.php @@ -0,0 +1,45 @@ + + */ +abstract class AbstractDescriptorCommand extends Command +{ + /** + * @var array + */ + private $supportedFormats; + + /** + * {@inheritdoc} + */ + protected function configure() + { + $descriptorProvider = new DescriptorProvider(); + $this->supportedFormats = $descriptorProvider->getSupportedFormats(); + $this->setDefinition($this->createDefinition()); + $this->getHelperSet()->set(new DescriptorHelper($descriptorProvider)); + } + + /** + * Creates command definition. + * + * @return InputDefinition + */ + protected function createDefinition() + { + return new InputDefinition(array( + new InputOption('format', null, InputOption::VALUE_OPTIONAL, 'Output format ('.implode(', ', $this->supportedFormats).')'), + new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'), + )); + } +} diff --git a/src/Symfony/Component/Console/Command/HelpCommand.php b/src/Symfony/Component/Console/Command/HelpCommand.php index ac4dd3d54d772..b467e710bc028 100644 --- a/src/Symfony/Component/Console/Command/HelpCommand.php +++ b/src/Symfony/Component/Console/Command/HelpCommand.php @@ -15,14 +15,13 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Command\Command; /** * HelpCommand displays the help for a given command. * * @author Fabien Potencier */ -class HelpCommand extends Command +class HelpCommand extends AbstractDescriptorCommand { private $command; @@ -35,10 +34,6 @@ protected function configure() $this ->setName('help') - ->setDefinition(array( - new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'), - new InputOption('xml', null, InputOption::VALUE_NONE, 'To output help as XML'), - )) ->setDescription('Displays help for a command') ->setHelp(<<%command.name% command displays help for a given command: @@ -65,6 +60,17 @@ public function setCommand(Command $command) $this->command = $command; } + /** + * {@inheritdoc} + */ + protected function createDefinition() + { + $definition = parent::createDefinition(); + $definition->addArgument(new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help')); + + return $definition; + } + /** * {@inheritdoc} */ @@ -74,11 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->command = $this->getApplication()->find($input->getArgument('command_name')); } - if ($input->getOption('xml')) { - $output->writeln($this->command->asXml(), OutputInterface::OUTPUT_RAW); - } else { - $output->writeln($this->command->asText()); - } + $this->getHelper('descriptor')->describe($output, $this->command, $input->getArgument('format'), $input->getOption('raw')); $this->command = null; } diff --git a/src/Symfony/Component/Console/Command/ListCommand.php b/src/Symfony/Component/Console/Command/ListCommand.php index ec5ea43e5b40e..e4c2f6025a63f 100644 --- a/src/Symfony/Component/Console/Command/ListCommand.php +++ b/src/Symfony/Component/Console/Command/ListCommand.php @@ -15,15 +15,13 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputDefinition; /** * ListCommand displays the list of all available commands for the application. * * @author Fabien Potencier */ -class ListCommand extends Command +class ListCommand extends AbstractDescriptorCommand { /** * {@inheritdoc} @@ -32,7 +30,6 @@ protected function configure() { $this ->setName('list') - ->setDefinition($this->createDefinition()) ->setDescription('Lists commands') ->setHelp(<<%command.name% command lists all commands: @@ -58,29 +55,27 @@ protected function configure() /** * {@inheritdoc} */ - protected function getNativeDefinition() + protected function createDefinition() { - return $this->createDefinition(); + $definition = parent::createDefinition(); + $definition->addArgument(new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name')); + + return $definition; } /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function getNativeDefinition() { - if ($input->getOption('xml')) { - $output->writeln($this->getApplication()->asXml($input->getArgument('namespace')), OutputInterface::OUTPUT_RAW); - } else { - $output->writeln($this->getApplication()->asText($input->getArgument('namespace'), $input->getOption('raw'))); - } + return $this->createDefinition(); } - private function createDefinition() + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) { - return new InputDefinition(array( - new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'), - new InputOption('xml', null, InputOption::VALUE_NONE, 'To output help as XML'), - new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'), - )); + $this->getHelper('descriptor')->describe($output, $this->getApplication(), $input->getArgument('format'), $input->getOption('raw')); } } diff --git a/src/Symfony/Component/Console/Descriptor/DescriptorInterface.php b/src/Symfony/Component/Console/Descriptor/DescriptorInterface.php new file mode 100644 index 0000000000000..39ffc8a805dcf --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/DescriptorInterface.php @@ -0,0 +1,51 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Descriptor; + +/** + * @author Jean-François Simon + */ +interface DescriptorInterface +{ + /** + * Returns given object's representation. + * + * @param object $object The object to describe + * @param boolean $raw No additional markers if true + * + * @return string The object formatted description + */ + public function describe($object, $raw = false); + + /** + * Tests if this descriptor supports given object. + * + * @param object $object The object to describe + * + * @return boolean + */ + public function supports($object); + + /** + * Returns descriptor's format name. + * + * @return string The format name + */ + public function getFormat(); + + /** + * Returns true if output formatting is used. + * + * @return boolean + */ + public function useFormatting(); +} diff --git a/src/Symfony/Component/Console/Descriptor/DescriptorProvider.php b/src/Symfony/Component/Console/Descriptor/DescriptorProvider.php new file mode 100644 index 0000000000000..ce4d35f495e5d --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/DescriptorProvider.php @@ -0,0 +1,89 @@ + + */ +class DescriptorProvider +{ + /** + * @var DescriptorInterface[] + */ + private $descriptors = array(); + + /** + * @var string + */ + private $defaultFormat; + + /** + * Constructor. + * + * @param string $defaultFormat + */ + public function __construct($defaultFormat = 'txt') + { + $this->defaultFormat = $defaultFormat; + } + + /** + * Adds a descriptor to the stack. + * + * @param DescriptorInterface $descriptor + * + * @return DescriptorProvider + */ + public function add(DescriptorInterface $descriptor) + { + $this->descriptors[] = $descriptor; + + return $this; + } + + /** + * Provides a descriptor for given object and format. + * + * @param mixed $object The object to describe + * @param string $format The description format + * + * @return DescriptorInterface The object descriptor + * + * @throws \InvalidArgumentException If no descriptors was found + */ + public function get($object, $format) + { + foreach ($this->descriptors as $descriptor) { + if ($format === $descriptor->getFormat() && $descriptor->supports($object)) { + return $descriptor; + } + } + + throw new \InvalidArgumentException(sprintf('Unsupported format "%s".', $format)); + } + + /** + * Returns default format. + * + * @return string + */ + public function getDefaultFormat() + { + return $this->defaultFormat; + } + + /** + * Returns supported formats list. + * + * @return array + */ + public function getSupportedFormats() + { + $supportedFormats = array(); + foreach ($this->descriptors as $descriptor) { + $supportedFormats[] = $descriptor->getFormat(); + } + + return array_unique($supportedFormats); + } +} diff --git a/src/Symfony/Component/Console/Helper/DescriptorHelper.php b/src/Symfony/Component/Console/Helper/DescriptorHelper.php new file mode 100644 index 0000000000000..b3d1e93937cf1 --- /dev/null +++ b/src/Symfony/Component/Console/Helper/DescriptorHelper.php @@ -0,0 +1,54 @@ + + */ +class DescriptorHelper extends Helper +{ + /** + * @var DescriptorProvider + */ + private $provider; + + /** + * Constructor. + * + * @param DescriptorProvider $provider + */ + public function __construct(DescriptorProvider $provider) + { + $this->provider = $provider; + } + + /** + * Describes an object if supported. + * + * @param OutputInterface $output + * @param object $object + * @param string $format + * @param boolean $raw + */ + public function describe(OutputInterface $output, $object, $format = null, $raw = false) + { + $format = $format ?: $this->provider->getDefaultFormat(); + $descriptor = $this->provider->get($object, $format); + $type = $raw && $descriptor->useFormatting() ? OutputInterface::OUTPUT_NORMAL : OutputInterface::OUTPUT_RAW; + + $output->writeln($descriptor->describe($object, $format, $raw), $type); + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return 'descriptor'; + } +} From f239b1c5c442b788b6c779ca110e34f97669f521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Mon, 1 Apr 2013 21:29:42 +0200 Subject: [PATCH 02/24] [Console] added JSON descriptors --- .../Descriptor/DescriptorInterface.php | 9 ++ .../Console/Descriptor/DescriptorProvider.php | 44 +++++++-- .../Json/AbstractJsonDescriptor.php | 81 +++++++++++++++++ .../Json/ApplicationJsonDescriptor.php | 90 +++++++++++++++++++ .../Descriptor/Json/CommandJsonDescriptor.php | 37 ++++++++ .../Json/InputArgumentJsonDescriptor.php | 34 +++++++ .../Json/InputDefinitionJsonDescriptor.php | 40 +++++++++ .../Json/InputOptionJsonDescriptor.php | 36 ++++++++ .../Descriptor/AbstractDescriptorTest.php | 32 +++++++ .../Json/ApplicationJsonDescriptorTest.php | 20 +++++ .../Json/CommandJsonDescriptorTest.php | 20 +++++ .../Json/InputArgumentJsonDescriptorTest.php | 20 +++++ .../InputDefinitionJsonDescriptorTest.php | 20 +++++ .../Json/InputOptionJsonDescriptorTest.php | 20 +++++ .../Tests/Descriptor/ObjectsProvider.php | 66 ++++++++++++++ .../Tests/Fixtures/DescriptorApplication1.php | 9 ++ .../Tests/Fixtures/DescriptorApplication2.php | 15 ++++ .../Tests/Fixtures/DescriptorCommand1.php | 18 ++++ .../Tests/Fixtures/DescriptorCommand2.php | 21 +++++ .../Console/Tests/Fixtures/application_1.json | 1 + .../Console/Tests/Fixtures/application_2.json | 1 + .../Console/Tests/Fixtures/command_1.json | 1 + .../Console/Tests/Fixtures/command_2.json | 1 + .../Tests/Fixtures/input_argument_1.json | 1 + .../Tests/Fixtures/input_argument_2.json | 1 + .../Tests/Fixtures/input_argument_3.json | 1 + .../Tests/Fixtures/input_definition_1.json | 1 + .../Tests/Fixtures/input_definition_2.json | 1 + .../Tests/Fixtures/input_definition_3.json | 1 + .../Tests/Fixtures/input_definition_4.json | 1 + .../Tests/Fixtures/input_option_1.json | 1 + .../Tests/Fixtures/input_option_2.json | 1 + .../Tests/Fixtures/input_option_3.json | 1 + .../Tests/Fixtures/input_option_4.json | 1 + 34 files changed, 641 insertions(+), 6 deletions(-) create mode 100644 src/Symfony/Component/Console/Descriptor/Json/AbstractJsonDescriptor.php create mode 100644 src/Symfony/Component/Console/Descriptor/Json/ApplicationJsonDescriptor.php create mode 100644 src/Symfony/Component/Console/Descriptor/Json/CommandJsonDescriptor.php create mode 100644 src/Symfony/Component/Console/Descriptor/Json/InputArgumentJsonDescriptor.php create mode 100644 src/Symfony/Component/Console/Descriptor/Json/InputDefinitionJsonDescriptor.php create mode 100644 src/Symfony/Component/Console/Descriptor/Json/InputOptionJsonDescriptor.php create mode 100644 src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php create mode 100644 src/Symfony/Component/Console/Tests/Descriptor/Json/ApplicationJsonDescriptorTest.php create mode 100644 src/Symfony/Component/Console/Tests/Descriptor/Json/CommandJsonDescriptorTest.php create mode 100644 src/Symfony/Component/Console/Tests/Descriptor/Json/InputArgumentJsonDescriptorTest.php create mode 100644 src/Symfony/Component/Console/Tests/Descriptor/Json/InputDefinitionJsonDescriptorTest.php create mode 100644 src/Symfony/Component/Console/Tests/Descriptor/Json/InputOptionJsonDescriptorTest.php create mode 100644 src/Symfony/Component/Console/Tests/Descriptor/ObjectsProvider.php create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplication1.php create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplication2.php create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand1.php create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand2.php create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_1.json create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_2.json create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/command_1.json create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/command_2.json create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_argument_1.json create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_argument_2.json create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_argument_3.json create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_definition_1.json create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_definition_2.json create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_definition_3.json create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_definition_4.json create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_1.json create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_2.json create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_3.json create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_4.json diff --git a/src/Symfony/Component/Console/Descriptor/DescriptorInterface.php b/src/Symfony/Component/Console/Descriptor/DescriptorInterface.php index 39ffc8a805dcf..fe9124f9243f5 100644 --- a/src/Symfony/Component/Console/Descriptor/DescriptorInterface.php +++ b/src/Symfony/Component/Console/Descriptor/DescriptorInterface.php @@ -16,6 +16,15 @@ */ interface DescriptorInterface { + /** + * Configures descriptor with description options. + * + * @param array $options Description options + * + * @return DescriptorInterface + */ + public function configure(array $options); + /** * Returns given object's representation. * diff --git a/src/Symfony/Component/Console/Descriptor/DescriptorProvider.php b/src/Symfony/Component/Console/Descriptor/DescriptorProvider.php index ce4d35f495e5d..f0cce3a3d696b 100644 --- a/src/Symfony/Component/Console/Descriptor/DescriptorProvider.php +++ b/src/Symfony/Component/Console/Descriptor/DescriptorProvider.php @@ -2,6 +2,8 @@ namespace Symfony\Component\Console\Descriptor; +use Symfony\Component\Console\Descriptor\Json; + /** * @author Jean-François Simon */ @@ -13,18 +15,29 @@ class DescriptorProvider private $descriptors = array(); /** - * @var string + * @var array */ - private $defaultFormat; + private $options = array( + 'default_format' => 'txt', + 'json_encoding' => 0, + 'namespace' => null, + ); /** * Constructor. * - * @param string $defaultFormat + * @param array $options */ - public function __construct($defaultFormat = 'txt') + public function __construct(array $options = array()) { - $this->defaultFormat = $defaultFormat; + $this + ->configure($options) + ->add(new Json\ApplicationJsonDescriptor()) + ->add(new Json\CommandJsonDescriptor()) + ->add(new Json\InputDefinitionJsonDescriptor()) + ->add(new Json\InputArgumentJsonDescriptor()) + ->add(new Json\InputOptionJsonDescriptor()) + ; } /** @@ -36,11 +49,30 @@ public function __construct($defaultFormat = 'txt') */ public function add(DescriptorInterface $descriptor) { + $descriptor->configure($this->options); $this->descriptors[] = $descriptor; return $this; } + /** + * Configures provider with options. + * + * @param array $options + * + * @return DescriptorProvider + */ + public function configure(array $options) + { + $this->options = array_replace($this->options, $options); + + foreach ($this->descriptors as $descriptor) { + $descriptor->configure($this->options); + } + + return $this; + } + /** * Provides a descriptor for given object and format. * @@ -69,7 +101,7 @@ public function get($object, $format) */ public function getDefaultFormat() { - return $this->defaultFormat; + return $this->options['default_format']; } /** diff --git a/src/Symfony/Component/Console/Descriptor/Json/AbstractJsonDescriptor.php b/src/Symfony/Component/Console/Descriptor/Json/AbstractJsonDescriptor.php new file mode 100644 index 0000000000000..cd55ead08973c --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Json/AbstractJsonDescriptor.php @@ -0,0 +1,81 @@ + + */ +abstract class AbstractJsonDescriptor implements DescriptorInterface +{ + /** + * @var int + */ + private $encodingOptions = 0; + + /** + * @param int $encodingOptions + */ + public function __construct($encodingOptions = 0) + { + $this->encodingOptions = $encodingOptions; + } + + /** + * {@inheritdoc} + */ + public function configure(array $options) + { + $this->encodingOptions = $options['json_encoding']; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function describe($object, $raw = false) + { + return json_encode($this->getData($object), $this->encodingOptions); + } + + /** + * Returns object data to encode. + * + * @param object $object + * + * @return array + */ + abstract public function getData($object); + + /** + * {@inheritdoc} + */ + public function getFormat() + { + return 'json'; + } + + /** + * {@inheritdoc} + */ + public function useFormatting() + { + return false; + } + + /** + * Builds a JSON descriptor. + * + * @param AbstractJsonDescriptor $descriptor + * + * @return AbstractJsonDescriptor + */ + protected function build(AbstractJsonDescriptor $descriptor) + { + $descriptor->configure(array('json_encoding' => $this->encodingOptions)); + + return $descriptor; + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Json/ApplicationJsonDescriptor.php b/src/Symfony/Component/Console/Descriptor/Json/ApplicationJsonDescriptor.php new file mode 100644 index 0000000000000..99168f31dec58 --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Json/ApplicationJsonDescriptor.php @@ -0,0 +1,90 @@ + + */ +class ApplicationJsonDescriptor extends AbstractJsonDescriptor +{ + /** + * @var string|null + */ + private $namespace; + + public function __construct($namespace = null, $encodingOptions = 0) + { + $this->namespace = $namespace; + parent::__construct($encodingOptions); + } + + + /** + * {@inheritdoc} + */ + public function configure(array $options) + { + $this->namespace = $options['namespace']; + + return parent::configure($options); + } + + /** + * {@inheritdoc} + */ + public function getData($object) + { + $commandDescriptor = $this->build(new CommandJsonDescriptor()); + + /** @var Application $object */ + $commands = $object->all($this->namespace ? $object->findNamespace($this->namespace) : null); + $data = array('commands' => array(), 'namespaces' => array()); + + foreach ($this->sortCommands($object, $commands) as $space => $commands) { + $namespaceData = array('id' => $space, 'commands' => array()); + + /** @var Command $command */ + foreach ($commands as $command) { + if (!$command->getName()) { + continue; + } + + $data['commands'][] = $commandDescriptor->getData($command); + $namespaceData['commands'][] = $command->getName(); + } + + $data['namespaces'][] = $namespaceData; + } + + if ($this->namespace) { + $data['namespace'] = $this->namespace; + } + + return $data; + } + + /** + * {@inheritdoc} + */ + public function supports($object) + { + return $object instanceof Application; + } + + /** + * @param Application $application + * @param Command[] $commands + * + * @return array + */ + private function sortCommands(Application $application, array $commands) + { + $method = new \ReflectionMethod($application, 'sortCommands'); + $method->setAccessible(true); + + return $method->invoke($application, $commands); + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Json/CommandJsonDescriptor.php b/src/Symfony/Component/Console/Descriptor/Json/CommandJsonDescriptor.php new file mode 100644 index 0000000000000..6731945d19ae1 --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Json/CommandJsonDescriptor.php @@ -0,0 +1,37 @@ + + */ +class CommandJsonDescriptor extends AbstractJsonDescriptor +{ + /** + * {@inheritdoc} + */ + public function getData($object) + { + $definitionDescriptor = $this->build(new InputDefinitionJsonDescriptor()); + + /** @var Command $object */ + return array( + 'name' => $object->getName(), + 'usage' => $object->getSynopsis(), + 'description' => $object->getDescription(), + 'help' => $object->getProcessedHelp(), + 'aliases' => $object->getAliases(), + 'definition' => $definitionDescriptor->getData($object->getDefinition()), + ); + } + + /** + * {@inheritdoc} + */ + public function supports($object) + { + return $object instanceof Command; + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Json/InputArgumentJsonDescriptor.php b/src/Symfony/Component/Console/Descriptor/Json/InputArgumentJsonDescriptor.php new file mode 100644 index 0000000000000..f786cf7ea8029 --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Json/InputArgumentJsonDescriptor.php @@ -0,0 +1,34 @@ + + */ +class InputArgumentJsonDescriptor extends AbstractJsonDescriptor +{ + /** + * {@inheritdoc} + */ + public function getData($object) + { + /** @var InputArgument $object */ + return array( + 'name' => $object->getName(), + 'is_required' => $object->isRequired(), + 'is_array' => $object->isArray(), + 'description' => $object->getDescription(), + 'default' => $object->getDefault(), + ); + } + + /** + * {@inheritdoc} + */ + public function supports($object) + { + return $object instanceof InputArgument; + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Json/InputDefinitionJsonDescriptor.php b/src/Symfony/Component/Console/Descriptor/Json/InputDefinitionJsonDescriptor.php new file mode 100644 index 0000000000000..4eca287b09f6e --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Json/InputDefinitionJsonDescriptor.php @@ -0,0 +1,40 @@ + + */ +class InputDefinitionJsonDescriptor extends AbstractJsonDescriptor +{ + /** + * {@inheritdoc} + */ + public function getData($object) + { + $argumentDescriptor = $this->build(new InputArgumentJsonDescriptor()); + $optionDescriptor = $this->build(new InputOptionJsonDescriptor()); + + /** @var InputDefinition $object */ + return array( + 'arguments' => array_map(function (InputArgument $argument) use ($argumentDescriptor) { + return $argumentDescriptor->getData($argument); + }, $object->getArguments()), + 'options' => array_map(function (InputOption $option) use ($optionDescriptor) { + return $optionDescriptor->getData($option); + }, $object->getOptions()), + ); + } + + /** + * {@inheritdoc} + */ + public function supports($object) + { + return $object instanceof InputDefinition; + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Json/InputOptionJsonDescriptor.php b/src/Symfony/Component/Console/Descriptor/Json/InputOptionJsonDescriptor.php new file mode 100644 index 0000000000000..83893da151cd5 --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Json/InputOptionJsonDescriptor.php @@ -0,0 +1,36 @@ + + */ +class InputOptionJsonDescriptor extends AbstractJsonDescriptor +{ + /** + * {@inheritdoc} + */ + public function getData($object) + { + /** @var InputOption $object */ + return array( + 'name' => '--'.$object->getName(), + 'shortcut' => $object->getShortcut() ? '-'.$object->getShortcut() : '', + 'accept_value' => $object->acceptValue(), + 'is_value_required' => $object->isValueRequired(), + 'is_multiple' => $object->isArray(), + 'description' => $object->getDescription(), + 'default' => $object->getDefault(), + ); + } + + /** + * {@inheritdoc} + */ + public function supports($object) + { + return $object instanceof InputOption; + } +} diff --git a/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php new file mode 100644 index 0000000000000..870d2408483b6 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php @@ -0,0 +1,32 @@ +assertTrue($descriptor->supports($object)); + $this->assertEquals(trim($description), trim($descriptor->describe($object))); + } + + public function getDescribeTestData() + { + $data = array(); + $descriptor = $this->getDescriptor(); + + foreach ($this->getObjects() as $name => $object) { + $description = file_get_contents(sprintf('%s/../Fixtures/%s.%s', __DIR__, $name, $descriptor->getFormat())); + $data[] = array($descriptor, $object, $description); + } + + return $data; + } + + abstract protected function getDescriptor(); + abstract protected function getObjects(); +} diff --git a/src/Symfony/Component/Console/Tests/Descriptor/Json/ApplicationJsonDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/Json/ApplicationJsonDescriptorTest.php new file mode 100644 index 0000000000000..948867cba3285 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Descriptor/Json/ApplicationJsonDescriptorTest.php @@ -0,0 +1,20 @@ + + */ +class ObjectsProvider +{ + public static function getInputArguments() + { + return array( + 'input_argument_1' => new InputArgument('argument_name', InputArgument::REQUIRED), + 'input_argument_2' => new InputArgument('argument_name', InputArgument::IS_ARRAY, 'argument description'), + 'input_argument_3' => new InputArgument('argument_name', InputArgument::OPTIONAL, 'argument description', 'default_value'), + ); + } + + public static function getInputOptions() + { + return array( + 'input_option_1' => new InputOption('option_name', 'o', InputOption::VALUE_NONE), + 'input_option_2' => new InputOption('option_name', 'o', InputOption::VALUE_OPTIONAL, 'option description', 'default_value'), + 'input_option_3' => new InputOption('option_name', 'o', InputOption::VALUE_REQUIRED, 'option description'), + 'input_option_4' => new InputOption('option_name', 'o', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'option description', array()), + ); + } + + public static function getInputDefinitions() + { + return array( + 'input_definition_1' => new InputDefinition(), + 'input_definition_2' => new InputDefinition(array(new InputArgument('argument_name', InputArgument::REQUIRED))), + 'input_definition_3' => new InputDefinition(array(new InputOption('option_name', 'o', InputOption::VALUE_NONE))), + 'input_definition_4' => new InputDefinition(array( + new InputArgument('argument_name', InputArgument::REQUIRED), + new InputOption('option_name', 'o', InputOption::VALUE_NONE), + )), + ); + } + + public static function getCommands() + { + return array( + 'command_1' => new DescriptorCommand1(), + 'command_2' => new DescriptorCommand2(), + ); + } + + public static function getApplications() + { + return array( + 'application_1' => new DescriptorApplication1(), + 'application_2' => new DescriptorApplication2(), + ); + } +} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplication1.php b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplication1.php new file mode 100644 index 0000000000000..6969b5806e567 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplication1.php @@ -0,0 +1,9 @@ +add(new DescriptorCommand1()); + $this->add(new DescriptorCommand2()); + } +} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand1.php b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand1.php new file mode 100644 index 0000000000000..380a7229f9cf0 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand1.php @@ -0,0 +1,18 @@ +setName('descriptor:command1') + ->setAliases(array('alias1', 'alias2')) + ->setDescription('command 1 description') + ->setHelp('command 1 help') + ; + } +} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand2.php b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand2.php new file mode 100644 index 0000000000000..f4c87c2cd4437 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand2.php @@ -0,0 +1,21 @@ +setName('descriptor:command2') + ->setDescription('command 2 description') + ->setHelp('command 2 help') + ->addArgument('argument_name', InputArgument::REQUIRED) + ->addOption('option_name', 'o', InputOption::VALUE_NONE) + ; + } +} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.json b/src/Symfony/Component/Console/Tests/Fixtures/application_1.json new file mode 100644 index 0000000000000..888d127f7b7de --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.json @@ -0,0 +1 @@ +{"commands":[{"name":"help","usage":"help","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php \/usr\/bin\/phpunit help list<\/info>\n\nYou can also output the help as XML by using the --xml<\/comment> option:\n\n php \/usr\/bin\/phpunit help --xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":[],"options":[]}},{"name":"list","usage":"list","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php \/usr\/bin\/phpunit list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php \/usr\/bin\/phpunit list test<\/info>\n\nYou can also output the information as XML by using the --xml<\/comment> option:\n\n php \/usr\/bin\/phpunit list --xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php \/usr\/bin\/phpunit list --raw<\/info>","aliases":[],"definition":{"arguments":[],"options":[]}}],"namespaces":[{"id":"_global","commands":["help","list"]}]} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.json b/src/Symfony/Component/Console/Tests/Fixtures/application_2.json new file mode 100644 index 0000000000000..b51e723476120 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.json @@ -0,0 +1 @@ +{"commands":[{"name":"descriptor:command1","usage":"descriptor:command1","description":"command 1 description","help":"command 1 help","aliases":["alias1","alias2"],"definition":{"arguments":[],"options":[]}},{"name":"descriptor:command1","usage":"descriptor:command1","description":"command 1 description","help":"command 1 help","aliases":["alias1","alias2"],"definition":{"arguments":[],"options":[]}},{"name":"help","usage":"help","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php \/usr\/bin\/phpunit help list<\/info>\n\nYou can also output the help as XML by using the --xml<\/comment> option:\n\n php \/usr\/bin\/phpunit help --xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":[],"options":[]}},{"name":"list","usage":"list","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php \/usr\/bin\/phpunit list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php \/usr\/bin\/phpunit list test<\/info>\n\nYou can also output the information as XML by using the --xml<\/comment> option:\n\n php \/usr\/bin\/phpunit list --xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php \/usr\/bin\/phpunit list --raw<\/info>","aliases":[],"definition":{"arguments":[],"options":[]}},{"name":"descriptor:command1","usage":"descriptor:command1","description":"command 1 description","help":"command 1 help","aliases":["alias1","alias2"],"definition":{"arguments":[],"options":[]}},{"name":"descriptor:command2","usage":"descriptor:command2 [-o|--option_name] argument_name","description":"command 2 description","help":"command 2 help","aliases":[],"definition":{"arguments":{"argument_name":{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null}},"options":{"option_name":{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false}}}}],"namespaces":[{"id":"_global","commands":["descriptor:command1","descriptor:command1","help","list"]},{"id":"descriptor","commands":["descriptor:command1","descriptor:command2"]}]} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/command_1.json b/src/Symfony/Component/Console/Tests/Fixtures/command_1.json new file mode 100644 index 0000000000000..0c1675dbcef42 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/command_1.json @@ -0,0 +1 @@ +{"name":"descriptor:command1","usage":"descriptor:command1","description":"command 1 description","help":"command 1 help","aliases":["alias1","alias2"],"definition":{"arguments":[],"options":[]}} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/command_2.json b/src/Symfony/Component/Console/Tests/Fixtures/command_2.json new file mode 100644 index 0000000000000..493b584669ef9 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/command_2.json @@ -0,0 +1 @@ +{"name":"descriptor:command2","usage":"descriptor:command2 [-o|--option_name] argument_name","description":"command 2 description","help":"command 2 help","aliases":[],"definition":{"arguments":{"argument_name":{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null}},"options":{"option_name":{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false}}}} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_argument_1.json b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_1.json new file mode 100644 index 0000000000000..b8173b6b3fca9 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_1.json @@ -0,0 +1 @@ +{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_argument_2.json b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_2.json new file mode 100644 index 0000000000000..ef06b09a7550f --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_2.json @@ -0,0 +1 @@ +{"name":"argument_name","is_required":false,"is_array":true,"description":"argument description","default":[]} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_argument_3.json b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_3.json new file mode 100644 index 0000000000000..de8484e6a72ce --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_3.json @@ -0,0 +1 @@ +{"name":"argument_name","is_required":false,"is_array":false,"description":"argument description","default":"default_value"} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_definition_1.json b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_1.json new file mode 100644 index 0000000000000..c7a7d838fd5ae --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_1.json @@ -0,0 +1 @@ +{"arguments":[],"options":[]} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_definition_2.json b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_2.json new file mode 100644 index 0000000000000..9964a55ae31ec --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_2.json @@ -0,0 +1 @@ +{"arguments":{"argument_name":{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null}},"options":[]} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_definition_3.json b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_3.json new file mode 100644 index 0000000000000..6a86056029784 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_3.json @@ -0,0 +1 @@ +{"arguments":[],"options":{"option_name":{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false}}} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_definition_4.json b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_4.json new file mode 100644 index 0000000000000..c5a0019fe2a1f --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_4.json @@ -0,0 +1 @@ +{"arguments":{"argument_name":{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null}},"options":{"option_name":{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false}}} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_1.json b/src/Symfony/Component/Console/Tests/Fixtures/input_option_1.json new file mode 100644 index 0000000000000..60c5b56cb44ea --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_1.json @@ -0,0 +1 @@ +{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_2.json b/src/Symfony/Component/Console/Tests/Fixtures/input_option_2.json new file mode 100644 index 0000000000000..04e4228ec3164 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_2.json @@ -0,0 +1 @@ +{"name":"--option_name","shortcut":"-o","accept_value":true,"is_value_required":false,"is_multiple":false,"description":"option description","default":"default_value"} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_3.json b/src/Symfony/Component/Console/Tests/Fixtures/input_option_3.json new file mode 100644 index 0000000000000..c1ea120c7a24a --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_3.json @@ -0,0 +1 @@ +{"name":"--option_name","shortcut":"-o","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"option description","default":null} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_4.json b/src/Symfony/Component/Console/Tests/Fixtures/input_option_4.json new file mode 100644 index 0000000000000..1b671d80651ef --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_4.json @@ -0,0 +1 @@ +{"name":"--option_name","shortcut":"-o","accept_value":true,"is_value_required":false,"is_multiple":true,"description":"option description","default":[]} From bebf1ebb2882b330bf7c9e17bb2be7045eb66f8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Wed, 3 Apr 2013 07:04:52 +0200 Subject: [PATCH 03/24] [Console] added markdown descriptors --- .../Descriptor/ApplicationDescription.php | 78 ++++++++++++++++ .../Json/AbstractJsonDescriptor.php | 2 +- .../Json/ApplicationJsonDescriptor.php | 52 +++-------- .../Markdown/AbstractMarkdownDescriptor.php | 67 ++++++++++++++ .../ApplicationMarkdownDescriptor.php | 70 ++++++++++++++ .../Markdown/CommandMarkdownDescriptor.php | 41 +++++++++ .../Markdown/Document/BlockInterface.php | 25 +++++ .../Descriptor/Markdown/Document/Document.php | 56 +++++++++++ .../Markdown/Document/Formatter.php | 55 +++++++++++ .../Markdown/Document/Paragraph.php | 40 ++++++++ .../Descriptor/Markdown/Document/Title.php | 71 ++++++++++++++ .../Markdown/Document/UnorderedList.php | 59 ++++++++++++ .../InputArgumentMarkdownDescriptor.php | 37 ++++++++ .../InputDefinitionMarkdownDescriptor.php | 47 ++++++++++ .../InputOptionMarkdownDescriptor.php | 39 ++++++++ .../ApplicationMarkdownDescriptorTest.php | 20 ++++ .../CommandMarkdownDescriptorTest.php | 20 ++++ .../Markdown/Document/FormatterTest.php | 27 ++++++ .../InputArgumentMarkdownDescriptorTest.php | 20 ++++ .../InputDefinitionMarkdownDescriptorTest.php | 20 ++++ .../InputOptionMarkdownDescriptorTest.php | 20 ++++ .../Tests/Fixtures/DescriptorApplication2.php | 2 +- .../Console/Tests/Fixtures/application_1.md | 45 +++++++++ .../Console/Tests/Fixtures/application_2.json | 2 +- .../Console/Tests/Fixtures/application_2.md | 92 +++++++++++++++++++ .../Console/Tests/Fixtures/command_1.md | 8 ++ .../Console/Tests/Fixtures/command_2.md | 30 ++++++ .../Tests/Fixtures/input_argument_1.md | 7 ++ .../Tests/Fixtures/input_argument_2.md | 7 ++ .../Tests/Fixtures/input_argument_3.md | 7 ++ .../Tests/Fixtures/input_definition_1.md | 0 .../Tests/Fixtures/input_definition_2.md | 9 ++ .../Tests/Fixtures/input_definition_3.md | 11 +++ .../Tests/Fixtures/input_definition_4.md | 21 +++++ .../Console/Tests/Fixtures/input_option_1.md | 9 ++ .../Console/Tests/Fixtures/input_option_2.md | 9 ++ .../Console/Tests/Fixtures/input_option_3.md | 9 ++ .../Console/Tests/Fixtures/input_option_4.md | 9 ++ 38 files changed, 1099 insertions(+), 44 deletions(-) create mode 100644 src/Symfony/Component/Console/Descriptor/ApplicationDescription.php create mode 100644 src/Symfony/Component/Console/Descriptor/Markdown/AbstractMarkdownDescriptor.php create mode 100644 src/Symfony/Component/Console/Descriptor/Markdown/ApplicationMarkdownDescriptor.php create mode 100644 src/Symfony/Component/Console/Descriptor/Markdown/CommandMarkdownDescriptor.php create mode 100644 src/Symfony/Component/Console/Descriptor/Markdown/Document/BlockInterface.php create mode 100644 src/Symfony/Component/Console/Descriptor/Markdown/Document/Document.php create mode 100644 src/Symfony/Component/Console/Descriptor/Markdown/Document/Formatter.php create mode 100644 src/Symfony/Component/Console/Descriptor/Markdown/Document/Paragraph.php create mode 100644 src/Symfony/Component/Console/Descriptor/Markdown/Document/Title.php create mode 100644 src/Symfony/Component/Console/Descriptor/Markdown/Document/UnorderedList.php create mode 100644 src/Symfony/Component/Console/Descriptor/Markdown/InputArgumentMarkdownDescriptor.php create mode 100644 src/Symfony/Component/Console/Descriptor/Markdown/InputDefinitionMarkdownDescriptor.php create mode 100644 src/Symfony/Component/Console/Descriptor/Markdown/InputOptionMarkdownDescriptor.php create mode 100644 src/Symfony/Component/Console/Tests/Descriptor/Markdown/ApplicationMarkdownDescriptorTest.php create mode 100644 src/Symfony/Component/Console/Tests/Descriptor/Markdown/CommandMarkdownDescriptorTest.php create mode 100644 src/Symfony/Component/Console/Tests/Descriptor/Markdown/Document/FormatterTest.php create mode 100644 src/Symfony/Component/Console/Tests/Descriptor/Markdown/InputArgumentMarkdownDescriptorTest.php create mode 100644 src/Symfony/Component/Console/Tests/Descriptor/Markdown/InputDefinitionMarkdownDescriptorTest.php create mode 100644 src/Symfony/Component/Console/Tests/Descriptor/Markdown/InputOptionMarkdownDescriptorTest.php create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_1.md create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_2.md create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/command_1.md create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/command_2.md create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_argument_1.md create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_argument_2.md create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_argument_3.md create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_definition_1.md create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_definition_2.md create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_definition_3.md create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_definition_4.md create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_1.md create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_2.md create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_3.md create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_4.md diff --git a/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php b/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php new file mode 100644 index 0000000000000..be5d9a4a5537d --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php @@ -0,0 +1,78 @@ + + */ +class ApplicationDescription +{ + const GLOBAL_NAMESPACE = '_global'; + + private $application; + private $namespace; + private $namespaces; + private $commands; + + public function __construct(Application $application, $namespace = null) + { + $this->application = $application; + $this->namespace = $namespace; + } + + public function getNamespaces() + { + if (null === $this->namespaces) { + $this->inspectApplication(); + } + + return $this->namespaces; + } + + public function getCommands() + { + if (null === $this->commands) { + $this->inspectApplication(); + } + + return $this->commands; + } + + private function inspectApplication() + { + $this->commands = array(); + $this->namespaces = array(); + + $all = $this->application->all($this->namespace ? $this->application->findNamespace($this->namespace) : null); + foreach ($this->sortCommands($all) as $namespace => $commands) { + $names = array(); + + /** @var Command $command */ + foreach ($commands as $name => $command) { + if (!$command->getName()) { + continue; + } + + // aliases must be skipped in commands list + if ($name === $command->getName()) { + $this->commands[] = $command; + } + + $names[] = $name; + } + + $this->namespaces[] = array('id' => $namespace, 'commands' => $names); + } + } + + private function sortCommands(array $commands) + { + $method = new \ReflectionMethod($this->application, 'sortCommands'); + $method->setAccessible(true); + + return $method->invoke($this->application, $commands); + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Json/AbstractJsonDescriptor.php b/src/Symfony/Component/Console/Descriptor/Json/AbstractJsonDescriptor.php index cd55ead08973c..a37f079707645 100644 --- a/src/Symfony/Component/Console/Descriptor/Json/AbstractJsonDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Json/AbstractJsonDescriptor.php @@ -12,7 +12,7 @@ abstract class AbstractJsonDescriptor implements DescriptorInterface /** * @var int */ - private $encodingOptions = 0; + private $encodingOptions; /** * @param int $encodingOptions diff --git a/src/Symfony/Component/Console/Descriptor/Json/ApplicationJsonDescriptor.php b/src/Symfony/Component/Console/Descriptor/Json/ApplicationJsonDescriptor.php index 99168f31dec58..6d2fe49ffeb3d 100644 --- a/src/Symfony/Component/Console/Descriptor/Json/ApplicationJsonDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Json/ApplicationJsonDescriptor.php @@ -3,7 +3,7 @@ namespace Symfony\Component\Console\Descriptor\Json; use Symfony\Component\Console\Application; -use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Descriptor\ApplicationDescription; /** * @author Jean-François Simon @@ -15,13 +15,16 @@ class ApplicationJsonDescriptor extends AbstractJsonDescriptor */ private $namespace; + /** + * @param string|null $namespace + * @param int $encodingOptions + */ public function __construct($namespace = null, $encodingOptions = 0) { $this->namespace = $namespace; parent::__construct($encodingOptions); } - /** * {@inheritdoc} */ @@ -37,33 +40,14 @@ public function configure(array $options) */ public function getData($object) { - $commandDescriptor = $this->build(new CommandJsonDescriptor()); - /** @var Application $object */ - $commands = $object->all($this->namespace ? $object->findNamespace($this->namespace) : null); - $data = array('commands' => array(), 'namespaces' => array()); - - foreach ($this->sortCommands($object, $commands) as $space => $commands) { - $namespaceData = array('id' => $space, 'commands' => array()); - - /** @var Command $command */ - foreach ($commands as $command) { - if (!$command->getName()) { - continue; - } - - $data['commands'][] = $commandDescriptor->getData($command); - $namespaceData['commands'][] = $command->getName(); - } - - $data['namespaces'][] = $namespaceData; - } + $description = new ApplicationDescription($object, $this->namespace); + $descriptor = $this->build(new CommandJsonDescriptor()); + $commands = array_map(array($descriptor, 'getData'), $description->getCommands()); - if ($this->namespace) { - $data['namespace'] = $this->namespace; - } - - return $data; + return null === $this->namespace + ? array('commands' => $commands, 'namespaces' => $description->getNamespaces()) + : array('commands' => $commands, 'namespace' => $this->namespace); } /** @@ -73,18 +57,4 @@ public function supports($object) { return $object instanceof Application; } - - /** - * @param Application $application - * @param Command[] $commands - * - * @return array - */ - private function sortCommands(Application $application, array $commands) - { - $method = new \ReflectionMethod($application, 'sortCommands'); - $method->setAccessible(true); - - return $method->invoke($application, $commands); - } } diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/AbstractMarkdownDescriptor.php b/src/Symfony/Component/Console/Descriptor/Markdown/AbstractMarkdownDescriptor.php new file mode 100644 index 0000000000000..c4c1f5470d881 --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Markdown/AbstractMarkdownDescriptor.php @@ -0,0 +1,67 @@ + + */ +abstract class AbstractMarkdownDescriptor implements DescriptorInterface +{ + /** + * @var int + */ + private $maxWidth; + + /** + * @param int $maxWidth + */ + public function __construct($maxWidth = 120) + { + $this->maxWidth = $maxWidth; + } + + /** + * {@inheritdoc} + */ + public function configure(array $options) + { + $this->maxWidth = $options['markdown_width']; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function describe($object, $raw = false) + { + return $this->getDocument($object)->format(new Document\Formatter($this->maxWidth)); + } + + /** + * Returns object document to format. + * + * @param object $object + * + * @return Document\Document + */ + abstract public function getDocument($object); + + /** + * {@inheritdoc} + */ + public function getFormat() + { + return 'md'; + } + + /** + * {@inheritdoc} + */ + public function useFormatting() + { + return false; + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/ApplicationMarkdownDescriptor.php b/src/Symfony/Component/Console/Descriptor/Markdown/ApplicationMarkdownDescriptor.php new file mode 100644 index 0000000000000..af22d5f0fa10a --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Markdown/ApplicationMarkdownDescriptor.php @@ -0,0 +1,70 @@ + + */ +class ApplicationMarkdownDescriptor extends AbstractMarkdownDescriptor +{ + /** + * @var string|null + */ + private $namespace; + + /** + * @param string|null $namespace + * @param int $maxWidth + */ + public function __construct($namespace = null, $maxWidth = 120) + { + $this->namespace = $namespace; + parent::__construct($maxWidth); + } + + /** + * {@inheritdoc} + */ + public function configure(array $options) + { + $this->namespace = $options['namespace']; + + return parent::configure($options); + } + + /** + * {@inheritdoc} + */ + public function getDocument($object) + { + /** @var Application $object */ + $description = new ApplicationDescription($object, $this->namespace); + $descriptor = new CommandMarkdownDescriptor(); + $document = new Document\Document(array(new Document\Title($object->getName(), 1))); + + foreach ($description->getNamespaces() as $namespace) { + if (ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) { + $document->add(new Document\Paragraph('**'.$namespace['id'].':**')); + } + + $document->add(new Document\UnorderedList($namespace['commands'])); + } + + foreach ($description->getCommands() as $command) { + $document->add($descriptor->getDocument($command)); + } + + return $document; + } + + /** + * {@inheritdoc} + */ + public function supports($object) + { + return $object instanceof Application; + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/CommandMarkdownDescriptor.php b/src/Symfony/Component/Console/Descriptor/Markdown/CommandMarkdownDescriptor.php new file mode 100644 index 0000000000000..48688e3f122d9 --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Markdown/CommandMarkdownDescriptor.php @@ -0,0 +1,41 @@ + + */ +class CommandMarkdownDescriptor extends AbstractMarkdownDescriptor +{ + /** + * {@inheritdoc} + */ + public function getDocument($object) + { + $definitionDescriptor = new InputDefinitionMarkdownDescriptor(); + + $object->getProcessedHelp(); + + /** @var Command $object */ + return new Document\Document(array( + new Document\Title($object->getName(), 2), + new Document\UnorderedList(array( + 'Description: '.($object->getDescription() ?: ''), + 'Usage: `'.$object->getSynopsis().'`', + 'Aliases: '.(count($object->getAliases()) ? '`'.implode('`, `', $object->getAliases()).'`' : ''), + )), + new Document\Paragraph($object->getProcessedHelp()), + $definitionDescriptor->getDocument($object->getDefinition()), + )); + } + + /** + * {@inheritdoc} + */ + public function supports($object) + { + return $object instanceof Command; + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/Document/BlockInterface.php b/src/Symfony/Component/Console/Descriptor/Markdown/Document/BlockInterface.php new file mode 100644 index 0000000000000..d4f3845e447b0 --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Markdown/Document/BlockInterface.php @@ -0,0 +1,25 @@ + + */ +interface BlockInterface +{ + /** + * @return boolean + */ + public function isEmpty(); + + /** + * Formats block output. + * + * @param Formatter $formatter + * + * @return string + */ + public function format(Formatter $formatter); +} diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/Document/Document.php b/src/Symfony/Component/Console/Descriptor/Markdown/Document/Document.php new file mode 100644 index 0000000000000..67ac4c63f1746 --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Markdown/Document/Document.php @@ -0,0 +1,56 @@ + + */ +class Document implements BlockInterface +{ + /** + * @var BlockInterface[] + */ + private $blocks = array(); + + /** + * @param BlockInterface[] $blocks + */ + public function __construct(array $blocks = array()) + { + foreach ($blocks as $block) { + $this->add($block); + } + } + + /** + * @param BlockInterface $block + * + * @return Document + */ + public function add(BlockInterface $block) + { + $this->blocks[] = $block; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function isEmpty() + { + return empty($this->blocks); + } + + /** + * {@inheritdoc} + */ + public function format(Formatter $formatter) + { + return implode("\n\n", array_map(function (BlockInterface $block) use ($formatter) { + return $block->format($formatter); + }, array_filter($this->blocks, function (BlockInterface $block) { + return !$block->isEmpty(); + }))); + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/Document/Formatter.php b/src/Symfony/Component/Console/Descriptor/Markdown/Document/Formatter.php new file mode 100644 index 0000000000000..7cbff31516744 --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Markdown/Document/Formatter.php @@ -0,0 +1,55 @@ + + */ +class Formatter +{ + /** + * @var int + */ + private $maxWidth; + + /** + * @param int $maxWidth + */ + public function __construct($maxWidth = 120) + { + $this->maxWidth = $maxWidth; + } + + /** + * Clips content on words. + * + * @param string $content Content to clip + * @param int $freeSpace Free space to keep + * + * @return array + */ + public function clip($content, $freeSpace = 0) + { + $lines = array(); + $maxWidth = $this->maxWidth - $freeSpace; + + foreach (explode("\n", $content) as $text) { + $line = ''; + foreach (explode(' ', $text) as $word) { + if (strlen($line.$word) <= $maxWidth) { + $line .= $word.' '; + continue; + } + + $lines[] = substr($line, 0, -1); + $line = $word.' '; + } + + if (!empty($line)) { + $lines[] = substr($line, 0, -1); + } + } + + return $lines; + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/Document/Paragraph.php b/src/Symfony/Component/Console/Descriptor/Markdown/Document/Paragraph.php new file mode 100644 index 0000000000000..39ac2239783a6 --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Markdown/Document/Paragraph.php @@ -0,0 +1,40 @@ + + */ +class Paragraph implements BlockInterface +{ + /** + * @var string + */ + private $content; + + /** + * @param $content + */ + public function __construct($content) + { + $this->content = $content; + } + + /** + * {@inheritdoc} + */ + public function isEmpty() + { + return empty($this->content); + } + + /** + * {@inheritdoc} + */ + public function format(Formatter $formatter) + { + return implode("\n", $formatter->clip($this->content)); + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/Document/Title.php b/src/Symfony/Component/Console/Descriptor/Markdown/Document/Title.php new file mode 100644 index 0000000000000..45818c895c471 --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Markdown/Document/Title.php @@ -0,0 +1,71 @@ + + */ +class Title implements BlockInterface +{ + /** + * @var string + */ + private $content; + + /** + * @var int + */ + private $level; + + /** + * @param string $content + * @param int $level + */ + public function __construct($content, $level = 1) + { + $this->content = $content; + $this->level = $level; + } + + /** + * {@inheritdoc} + */ + public function isEmpty() + { + return empty($this->content); + } + + /** + * {@inheritdoc} + */ + public function format(Formatter $formatter) + { + if (empty($this->content)) { + return ''; + } + + switch ($this->level) { + case 1: return $this->entitle('='); + case 2: return $this->entitle('-'); + } + + $lines = array(); + foreach ($formatter->clip($this->content, $this->level + 1) as $index => $line) { + $lines[] = (0 === $index ? str_repeat('#', $this->level).' ' : str_repeat(' ', $this->level + 1)).$line; + } + + return implode("\n", $lines); + } + + /** + * @param string $char + * + * @return string + */ + private function entitle($char) + { + return $this->content."\n".str_repeat($char, strlen($this->content)); + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/Document/UnorderedList.php b/src/Symfony/Component/Console/Descriptor/Markdown/Document/UnorderedList.php new file mode 100644 index 0000000000000..0953933adaddf --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Markdown/Document/UnorderedList.php @@ -0,0 +1,59 @@ + + */ +class UnorderedList implements BlockInterface +{ + /** + * @var array + */ + private $items; + + /** + * @param array $items + */ + public function __construct(array $items = array()) + { + $this->items = $items; + } + + /** + * @param $item + * + * @return UnorderedList + */ + public function push($item) + { + $this->items[] = $item; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function isEmpty() + { + return empty($this->items); + } + + /** + * {@inheritdoc} + */ + public function format(Formatter $formatter) + { + $content = array(); + foreach ($this->items as $item) { + foreach ($formatter->clip($item, 2) as $index => $line) { + $content[] = (0 === $index ? '* ' : ' ').$line; + } + } + + return implode("\n", $content); + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/InputArgumentMarkdownDescriptor.php b/src/Symfony/Component/Console/Descriptor/Markdown/InputArgumentMarkdownDescriptor.php new file mode 100644 index 0000000000000..cac884376db1e --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Markdown/InputArgumentMarkdownDescriptor.php @@ -0,0 +1,37 @@ + + */ +class InputArgumentMarkdownDescriptor extends AbstractMarkdownDescriptor +{ + /** + * {@inheritdoc} + */ + public function getDocument($object) + { + /** @var InputArgument $object */ + return new Document\Document(array( + new Document\Paragraph('**'.$object->getName().':**'), + new Document\UnorderedList(array( + 'Name: '.($object->getName() ?: ''), + 'Is required: '.($object->isRequired() ? 'yes' : 'no'), + 'Is array: '.($object->isArray() ? 'yes' : 'no'), + 'Description: '.($object->getDescription() ?: ''), + 'Default: `'.str_replace("\n", '', var_export($object->getDefault(), true)).'`', + )), + )); + } + + /** + * {@inheritdoc} + */ + public function supports($object) + { + return $object instanceof InputArgument; + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/InputDefinitionMarkdownDescriptor.php b/src/Symfony/Component/Console/Descriptor/Markdown/InputDefinitionMarkdownDescriptor.php new file mode 100644 index 0000000000000..36b3691ad359b --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Markdown/InputDefinitionMarkdownDescriptor.php @@ -0,0 +1,47 @@ + + */ +class InputDefinitionMarkdownDescriptor extends AbstractMarkdownDescriptor +{ + /** + * {@inheritdoc} + */ + public function getDocument($object) + { + $document = new Document\Document(); + $argumentDescriptor = new InputArgumentMarkdownDescriptor(); + $optionDescriptor = new InputOptionMarkdownDescriptor(); + + /** @var InputDefinition $object */ + + if (count($object->getArguments()) > 0) { + $document->add(new Document\Title('Arguments:', 3)); + foreach ($object->getArguments() as $argument) { + $document->add($argumentDescriptor->getDocument($argument)); + } + } + + if (count($object->getOptions()) > 0) { + $document->add(new Document\Title('Options:', 3)); + foreach ($object->getOptions() as $option) { + $document->add($optionDescriptor->getDocument($option)); + } + } + + return $document; + } + + /** + * {@inheritdoc} + */ + public function supports($object) + { + return $object instanceof InputDefinition; + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/InputOptionMarkdownDescriptor.php b/src/Symfony/Component/Console/Descriptor/Markdown/InputOptionMarkdownDescriptor.php new file mode 100644 index 0000000000000..84e2b751638c7 --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Markdown/InputOptionMarkdownDescriptor.php @@ -0,0 +1,39 @@ + + */ +class InputOptionMarkdownDescriptor extends AbstractMarkdownDescriptor +{ + /** + * {@inheritdoc} + */ + public function getDocument($object) + { + /** @var InputOption $object */ + return new Document\Document(array( + new Document\Paragraph('**'.$object->getName().':**'), + new Document\UnorderedList(array( + 'Name: `--'.$object->getName().'`', + 'Shortcut: '.($object->getShortcut() ? '`-'.$object->getShortcut().'`' : ''), + 'Accept value: '.($object->acceptValue() ? 'yes' : 'no'), + 'Is value required: '.($object->isValueRequired() ? 'yes' : 'no'), + 'Is multiple: '.($object->isArray() ? 'yes' : 'no'), + 'Description: '.($object->getDescription() ?: ''), + 'Default: `'.str_replace("\n", '', var_export($object->getDefault(), true)).'`', + )), + )); + } + + /** + * {@inheritdoc} + */ + public function supports($object) + { + return $object instanceof InputOption; + } +} diff --git a/src/Symfony/Component/Console/Tests/Descriptor/Markdown/ApplicationMarkdownDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/Markdown/ApplicationMarkdownDescriptorTest.php new file mode 100644 index 0000000000000..3864547be425f --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Descriptor/Markdown/ApplicationMarkdownDescriptorTest.php @@ -0,0 +1,20 @@ +assertEquals($expectedLines, $formatter->clip($content)); + } + + public function getClipTestData() + { + $lorem = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit.'; + + return array( + array('a b c d e', 3, array('a b', 'c d', 'e')), + array($lorem, 20, array('Lorem ipsum dolor', 'sit amet,', 'consectetur', 'adipisicing elit.')), + array($lorem, 30, array('Lorem ipsum dolor sit amet,', 'consectetur adipisicing elit.')), + array($lorem, 60, array($lorem)), + ); + } +} \ No newline at end of file diff --git a/src/Symfony/Component/Console/Tests/Descriptor/Markdown/InputArgumentMarkdownDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/Markdown/InputArgumentMarkdownDescriptorTest.php new file mode 100644 index 0000000000000..03d4fb4153600 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Descriptor/Markdown/InputArgumentMarkdownDescriptorTest.php @@ -0,0 +1,20 @@ +add(new DescriptorCommand1()); $this->add(new DescriptorCommand2()); } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.md b/src/Symfony/Component/Console/Tests/Fixtures/application_1.md new file mode 100644 index 0000000000000..8a66309fd4fb4 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.md @@ -0,0 +1,45 @@ +UNKNOWN +======= + +* help +* list + +help +---- + +* Description: Displays help for a command +* Usage: `help` +* Aliases: + +The help command displays help for a given command: + + php /usr/bin/phpunit help list + +You can also output the help as XML by using the --xml option: + + php /usr/bin/phpunit help --xml list + +To display the list of available commands, please use the list command. + +list +---- + +* Description: Lists commands +* Usage: `list` +* Aliases: + +The list command lists all commands: + + php /usr/bin/phpunit list + +You can also display the commands for a specific namespace: + + php /usr/bin/phpunit list test + +You can also output the information as XML by using the --xml option: + + php /usr/bin/phpunit list --xml + +It's also possible to get raw list of commands (useful for embedding command runner): + + php /usr/bin/phpunit list --raw diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.json b/src/Symfony/Component/Console/Tests/Fixtures/application_2.json index b51e723476120..0176a6221140b 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_2.json +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.json @@ -1 +1 @@ -{"commands":[{"name":"descriptor:command1","usage":"descriptor:command1","description":"command 1 description","help":"command 1 help","aliases":["alias1","alias2"],"definition":{"arguments":[],"options":[]}},{"name":"descriptor:command1","usage":"descriptor:command1","description":"command 1 description","help":"command 1 help","aliases":["alias1","alias2"],"definition":{"arguments":[],"options":[]}},{"name":"help","usage":"help","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php \/usr\/bin\/phpunit help list<\/info>\n\nYou can also output the help as XML by using the --xml<\/comment> option:\n\n php \/usr\/bin\/phpunit help --xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":[],"options":[]}},{"name":"list","usage":"list","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php \/usr\/bin\/phpunit list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php \/usr\/bin\/phpunit list test<\/info>\n\nYou can also output the information as XML by using the --xml<\/comment> option:\n\n php \/usr\/bin\/phpunit list --xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php \/usr\/bin\/phpunit list --raw<\/info>","aliases":[],"definition":{"arguments":[],"options":[]}},{"name":"descriptor:command1","usage":"descriptor:command1","description":"command 1 description","help":"command 1 help","aliases":["alias1","alias2"],"definition":{"arguments":[],"options":[]}},{"name":"descriptor:command2","usage":"descriptor:command2 [-o|--option_name] argument_name","description":"command 2 description","help":"command 2 help","aliases":[],"definition":{"arguments":{"argument_name":{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null}},"options":{"option_name":{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false}}}}],"namespaces":[{"id":"_global","commands":["descriptor:command1","descriptor:command1","help","list"]},{"id":"descriptor","commands":["descriptor:command1","descriptor:command2"]}]} +{"commands":[{"name":"help","usage":"help","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php \/usr\/bin\/phpunit help list<\/info>\n\nYou can also output the help as XML by using the --xml<\/comment> option:\n\n php \/usr\/bin\/phpunit help --xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":[],"options":[]}},{"name":"list","usage":"list","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php \/usr\/bin\/phpunit list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php \/usr\/bin\/phpunit list test<\/info>\n\nYou can also output the information as XML by using the --xml<\/comment> option:\n\n php \/usr\/bin\/phpunit list --xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php \/usr\/bin\/phpunit list --raw<\/info>","aliases":[],"definition":{"arguments":[],"options":[]}},{"name":"descriptor:command1","usage":"descriptor:command1","description":"command 1 description","help":"command 1 help","aliases":["alias1","alias2"],"definition":{"arguments":[],"options":[]}},{"name":"descriptor:command2","usage":"descriptor:command2 [-o|--option_name] argument_name","description":"command 2 description","help":"command 2 help","aliases":[],"definition":{"arguments":{"argument_name":{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null}},"options":{"option_name":{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false}}}}],"namespaces":[{"id":"_global","commands":["alias1","alias2","help","list"]},{"id":"descriptor","commands":["descriptor:command1","descriptor:command2"]}]} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.md b/src/Symfony/Component/Console/Tests/Fixtures/application_2.md new file mode 100644 index 0000000000000..baa59dfcdc867 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.md @@ -0,0 +1,92 @@ +My Symfony application +====================== + +* alias1 +* alias2 +* help +* list + +**descriptor:** + +* descriptor:command1 +* descriptor:command2 + +help +---- + +* Description: Displays help for a command +* Usage: `help` +* Aliases: + +The help command displays help for a given command: + + php /usr/bin/phpunit help list + +You can also output the help as XML by using the --xml option: + + php /usr/bin/phpunit help --xml list + +To display the list of available commands, please use the list command. + +list +---- + +* Description: Lists commands +* Usage: `list` +* Aliases: + +The list command lists all commands: + + php /usr/bin/phpunit list + +You can also display the commands for a specific namespace: + + php /usr/bin/phpunit list test + +You can also output the information as XML by using the --xml option: + + php /usr/bin/phpunit list --xml + +It's also possible to get raw list of commands (useful for embedding command runner): + + php /usr/bin/phpunit list --raw + +descriptor:command1 +------------------- + +* Description: command 1 description +* Usage: `descriptor:command1` +* Aliases: `alias1`, `alias2` + +command 1 help + +descriptor:command2 +------------------- + +* Description: command 2 description +* Usage: `descriptor:command2 [-o|--option_name] argument_name` +* Aliases: + +command 2 help + +### Arguments: + +**argument_name:** + +* Name: argument_name +* Is required: yes +* Is array: no +* Description: +* Default: `NULL` + +### Options: + +**option_name:** + +* Name: `--option_name` +* Shortcut: `-o` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: +* Default: `false` diff --git a/src/Symfony/Component/Console/Tests/Fixtures/command_1.md b/src/Symfony/Component/Console/Tests/Fixtures/command_1.md new file mode 100644 index 0000000000000..2cef9a2d781ed --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/command_1.md @@ -0,0 +1,8 @@ +descriptor:command1 +------------------- + +* Description: command 1 description +* Usage: `descriptor:command1` +* Aliases: `alias1`, `alias2` + +command 1 help diff --git a/src/Symfony/Component/Console/Tests/Fixtures/command_2.md b/src/Symfony/Component/Console/Tests/Fixtures/command_2.md new file mode 100644 index 0000000000000..5257c0d3f2cfc --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/command_2.md @@ -0,0 +1,30 @@ +descriptor:command2 +------------------- + +* Description: command 2 description +* Usage: `descriptor:command2 [-o|--option_name] argument_name` +* Aliases: + +command 2 help + +### Arguments: + +**argument_name:** + +* Name: argument_name +* Is required: yes +* Is array: no +* Description: +* Default: `NULL` + +### Options: + +**option_name:** + +* Name: `--option_name` +* Shortcut: `-o` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: +* Default: `false` diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_argument_1.md b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_1.md new file mode 100644 index 0000000000000..88f311ab534b1 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_1.md @@ -0,0 +1,7 @@ +**argument_name:** + +* Name: argument_name +* Is required: yes +* Is array: no +* Description: +* Default: `NULL` diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_argument_2.md b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_2.md new file mode 100644 index 0000000000000..3cdb00cc81867 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_2.md @@ -0,0 +1,7 @@ +**argument_name:** + +* Name: argument_name +* Is required: no +* Is array: yes +* Description: argument description +* Default: `array ()` diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_argument_3.md b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_3.md new file mode 100644 index 0000000000000..be1c443ae0dcf --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_3.md @@ -0,0 +1,7 @@ +**argument_name:** + +* Name: argument_name +* Is required: no +* Is array: no +* Description: argument description +* Default: `'default_value'` diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_definition_1.md b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_1.md new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_definition_2.md b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_2.md new file mode 100644 index 0000000000000..923191cdcf9f2 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_2.md @@ -0,0 +1,9 @@ +### Arguments: + +**argument_name:** + +* Name: argument_name +* Is required: yes +* Is array: no +* Description: +* Default: `NULL` diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_definition_3.md b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_3.md new file mode 100644 index 0000000000000..40fd7b0a973cb --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_3.md @@ -0,0 +1,11 @@ +### Options: + +**option_name:** + +* Name: `--option_name` +* Shortcut: `-o` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: +* Default: `false` diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_definition_4.md b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_4.md new file mode 100644 index 0000000000000..a31feea477cd9 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_4.md @@ -0,0 +1,21 @@ +### Arguments: + +**argument_name:** + +* Name: argument_name +* Is required: yes +* Is array: no +* Description: +* Default: `NULL` + +### Options: + +**option_name:** + +* Name: `--option_name` +* Shortcut: `-o` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: +* Default: `false` diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_1.md b/src/Symfony/Component/Console/Tests/Fixtures/input_option_1.md new file mode 100644 index 0000000000000..6f9e9a7e074c6 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_1.md @@ -0,0 +1,9 @@ +**option_name:** + +* Name: `--option_name` +* Shortcut: `-o` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: +* Default: `false` diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_2.md b/src/Symfony/Component/Console/Tests/Fixtures/input_option_2.md new file mode 100644 index 0000000000000..634ac0b03c02c --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_2.md @@ -0,0 +1,9 @@ +**option_name:** + +* Name: `--option_name` +* Shortcut: `-o` +* Accept value: yes +* Is value required: no +* Is multiple: no +* Description: option description +* Default: `'default_value'` diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_3.md b/src/Symfony/Component/Console/Tests/Fixtures/input_option_3.md new file mode 100644 index 0000000000000..34282896ba39a --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_3.md @@ -0,0 +1,9 @@ +**option_name:** + +* Name: `--option_name` +* Shortcut: `-o` +* Accept value: yes +* Is value required: yes +* Is multiple: no +* Description: option description +* Default: `NULL` diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_4.md b/src/Symfony/Component/Console/Tests/Fixtures/input_option_4.md new file mode 100644 index 0000000000000..8ffba56e73265 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_4.md @@ -0,0 +1,9 @@ +**option_name:** + +* Name: `--option_name` +* Shortcut: `-o` +* Accept value: yes +* Is value required: no +* Is multiple: yes +* Description: option description +* Default: `array ()` From 43b5e5c2f98ae276057910d44111a9ecd038c2bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Wed, 3 Apr 2013 07:06:30 +0200 Subject: [PATCH 04/24] [Console] added forgotten headers --- .../Console/Command/AbstractDescriptorCommand.php | 9 +++++++++ .../Console/Descriptor/ApplicationDescription.php | 9 +++++++++ .../Console/Descriptor/DescriptorProvider.php | 9 +++++++++ .../Descriptor/Json/AbstractJsonDescriptor.php | 9 +++++++++ .../Descriptor/Json/ApplicationJsonDescriptor.php | 9 +++++++++ .../Console/Descriptor/Json/CommandJsonDescriptor.php | 9 +++++++++ .../Descriptor/Json/InputArgumentJsonDescriptor.php | 9 +++++++++ .../Descriptor/Json/InputDefinitionJsonDescriptor.php | 9 +++++++++ .../Descriptor/Json/InputOptionJsonDescriptor.php | 9 +++++++++ .../Markdown/AbstractMarkdownDescriptor.php | 9 +++++++++ .../Markdown/ApplicationMarkdownDescriptor.php | 9 +++++++++ .../Descriptor/Markdown/CommandMarkdownDescriptor.php | 9 +++++++++ .../Descriptor/Markdown/Document/BlockInterface.php | 9 +++++++++ .../Console/Descriptor/Markdown/Document/Document.php | 9 +++++++++ .../Descriptor/Markdown/Document/Formatter.php | 9 +++++++++ .../Descriptor/Markdown/Document/Paragraph.php | 9 +++++++++ .../Console/Descriptor/Markdown/Document/Title.php | 9 +++++++++ .../Descriptor/Markdown/Document/UnorderedList.php | 9 +++++++++ .../Markdown/InputArgumentMarkdownDescriptor.php | 9 +++++++++ .../Markdown/InputDefinitionMarkdownDescriptor.php | 9 +++++++++ .../Markdown/InputOptionMarkdownDescriptor.php | 9 +++++++++ .../Component/Console/Helper/DescriptorHelper.php | 9 +++++++++ .../Tests/Descriptor/AbstractDescriptorTest.php | 9 +++++++++ .../Descriptor/Json/ApplicationJsonDescriptorTest.php | 9 +++++++++ .../Descriptor/Json/CommandJsonDescriptorTest.php | 9 +++++++++ .../Json/InputArgumentJsonDescriptorTest.php | 9 +++++++++ .../Json/InputDefinitionJsonDescriptorTest.php | 9 +++++++++ .../Descriptor/Json/InputOptionJsonDescriptorTest.php | 9 +++++++++ .../Markdown/ApplicationMarkdownDescriptorTest.php | 9 +++++++++ .../Markdown/CommandMarkdownDescriptorTest.php | 9 +++++++++ .../Descriptor/Markdown/Document/FormatterTest.php | 11 ++++++++++- .../Markdown/InputArgumentMarkdownDescriptorTest.php | 9 +++++++++ .../InputDefinitionMarkdownDescriptorTest.php | 9 +++++++++ .../Markdown/InputOptionMarkdownDescriptorTest.php | 9 +++++++++ .../Console/Tests/Descriptor/ObjectsProvider.php | 9 +++++++++ .../Console/Tests/Fixtures/DescriptorApplication1.php | 9 +++++++++ .../Console/Tests/Fixtures/DescriptorApplication2.php | 9 +++++++++ .../Console/Tests/Fixtures/DescriptorCommand1.php | 9 +++++++++ .../Console/Tests/Fixtures/DescriptorCommand2.php | 9 +++++++++ 39 files changed, 352 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Command/AbstractDescriptorCommand.php b/src/Symfony/Component/Console/Command/AbstractDescriptorCommand.php index 3564b84e02d33..c3ccdf6e3bc78 100644 --- a/src/Symfony/Component/Console/Command/AbstractDescriptorCommand.php +++ b/src/Symfony/Component/Console/Command/AbstractDescriptorCommand.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Command; use Symfony\Component\Console\Descriptor\DescriptorProvider; diff --git a/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php b/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php index be5d9a4a5537d..775be0fbbc9bc 100644 --- a/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php +++ b/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Descriptor; use Symfony\Component\Console\Application; diff --git a/src/Symfony/Component/Console/Descriptor/DescriptorProvider.php b/src/Symfony/Component/Console/Descriptor/DescriptorProvider.php index f0cce3a3d696b..ca8b835ac51b6 100644 --- a/src/Symfony/Component/Console/Descriptor/DescriptorProvider.php +++ b/src/Symfony/Component/Console/Descriptor/DescriptorProvider.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Descriptor; use Symfony\Component\Console\Descriptor\Json; diff --git a/src/Symfony/Component/Console/Descriptor/Json/AbstractJsonDescriptor.php b/src/Symfony/Component/Console/Descriptor/Json/AbstractJsonDescriptor.php index a37f079707645..39603108086a2 100644 --- a/src/Symfony/Component/Console/Descriptor/Json/AbstractJsonDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Json/AbstractJsonDescriptor.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Descriptor\Json; use Symfony\Component\Console\Descriptor\DescriptorInterface; diff --git a/src/Symfony/Component/Console/Descriptor/Json/ApplicationJsonDescriptor.php b/src/Symfony/Component/Console/Descriptor/Json/ApplicationJsonDescriptor.php index 6d2fe49ffeb3d..356b4ed71e3d4 100644 --- a/src/Symfony/Component/Console/Descriptor/Json/ApplicationJsonDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Json/ApplicationJsonDescriptor.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Descriptor\Json; use Symfony\Component\Console\Application; diff --git a/src/Symfony/Component/Console/Descriptor/Json/CommandJsonDescriptor.php b/src/Symfony/Component/Console/Descriptor/Json/CommandJsonDescriptor.php index 6731945d19ae1..d4bd698180a3b 100644 --- a/src/Symfony/Component/Console/Descriptor/Json/CommandJsonDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Json/CommandJsonDescriptor.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Descriptor\Json; use Symfony\Component\Console\Command\Command; diff --git a/src/Symfony/Component/Console/Descriptor/Json/InputArgumentJsonDescriptor.php b/src/Symfony/Component/Console/Descriptor/Json/InputArgumentJsonDescriptor.php index f786cf7ea8029..fe9b9ca63fb71 100644 --- a/src/Symfony/Component/Console/Descriptor/Json/InputArgumentJsonDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Json/InputArgumentJsonDescriptor.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Descriptor\Json; use Symfony\Component\Console\Input\InputArgument; diff --git a/src/Symfony/Component/Console/Descriptor/Json/InputDefinitionJsonDescriptor.php b/src/Symfony/Component/Console/Descriptor/Json/InputDefinitionJsonDescriptor.php index 4eca287b09f6e..4755b0980bc53 100644 --- a/src/Symfony/Component/Console/Descriptor/Json/InputDefinitionJsonDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Json/InputDefinitionJsonDescriptor.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Descriptor\Json; use Symfony\Component\Console\Input\InputArgument; diff --git a/src/Symfony/Component/Console/Descriptor/Json/InputOptionJsonDescriptor.php b/src/Symfony/Component/Console/Descriptor/Json/InputOptionJsonDescriptor.php index 83893da151cd5..329c813d48b6b 100644 --- a/src/Symfony/Component/Console/Descriptor/Json/InputOptionJsonDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Json/InputOptionJsonDescriptor.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Descriptor\Json; use Symfony\Component\Console\Input\InputOption; diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/AbstractMarkdownDescriptor.php b/src/Symfony/Component/Console/Descriptor/Markdown/AbstractMarkdownDescriptor.php index c4c1f5470d881..2c00b30067ee4 100644 --- a/src/Symfony/Component/Console/Descriptor/Markdown/AbstractMarkdownDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Markdown/AbstractMarkdownDescriptor.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Descriptor\Markdown; use Symfony\Component\Console\Descriptor\DescriptorInterface; diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/ApplicationMarkdownDescriptor.php b/src/Symfony/Component/Console/Descriptor/Markdown/ApplicationMarkdownDescriptor.php index af22d5f0fa10a..64b61a4488459 100644 --- a/src/Symfony/Component/Console/Descriptor/Markdown/ApplicationMarkdownDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Markdown/ApplicationMarkdownDescriptor.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Descriptor\Markdown; use Symfony\Component\Console\Application; diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/CommandMarkdownDescriptor.php b/src/Symfony/Component/Console/Descriptor/Markdown/CommandMarkdownDescriptor.php index 48688e3f122d9..4e8a509ccf9a0 100644 --- a/src/Symfony/Component/Console/Descriptor/Markdown/CommandMarkdownDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Markdown/CommandMarkdownDescriptor.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Descriptor\Markdown; use Symfony\Component\Console\Command\Command; diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/Document/BlockInterface.php b/src/Symfony/Component/Console/Descriptor/Markdown/Document/BlockInterface.php index d4f3845e447b0..ce39fac8a43d8 100644 --- a/src/Symfony/Component/Console/Descriptor/Markdown/Document/BlockInterface.php +++ b/src/Symfony/Component/Console/Descriptor/Markdown/Document/BlockInterface.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Descriptor\Markdown\Document; /** diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/Document/Document.php b/src/Symfony/Component/Console/Descriptor/Markdown/Document/Document.php index 67ac4c63f1746..6cf2ef7e77cc4 100644 --- a/src/Symfony/Component/Console/Descriptor/Markdown/Document/Document.php +++ b/src/Symfony/Component/Console/Descriptor/Markdown/Document/Document.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Descriptor\Markdown\Document; /** diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/Document/Formatter.php b/src/Symfony/Component/Console/Descriptor/Markdown/Document/Formatter.php index 7cbff31516744..2669a0353939c 100644 --- a/src/Symfony/Component/Console/Descriptor/Markdown/Document/Formatter.php +++ b/src/Symfony/Component/Console/Descriptor/Markdown/Document/Formatter.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Descriptor\Markdown\Document; /** diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/Document/Paragraph.php b/src/Symfony/Component/Console/Descriptor/Markdown/Document/Paragraph.php index 39ac2239783a6..4fe3beeb360b0 100644 --- a/src/Symfony/Component/Console/Descriptor/Markdown/Document/Paragraph.php +++ b/src/Symfony/Component/Console/Descriptor/Markdown/Document/Paragraph.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Descriptor\Markdown\Document; /** diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/Document/Title.php b/src/Symfony/Component/Console/Descriptor/Markdown/Document/Title.php index 45818c895c471..45cfc3d14092b 100644 --- a/src/Symfony/Component/Console/Descriptor/Markdown/Document/Title.php +++ b/src/Symfony/Component/Console/Descriptor/Markdown/Document/Title.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Descriptor\Markdown\Document; /** diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/Document/UnorderedList.php b/src/Symfony/Component/Console/Descriptor/Markdown/Document/UnorderedList.php index 0953933adaddf..a228ed6185728 100644 --- a/src/Symfony/Component/Console/Descriptor/Markdown/Document/UnorderedList.php +++ b/src/Symfony/Component/Console/Descriptor/Markdown/Document/UnorderedList.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Descriptor\Markdown\Document; /** diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/InputArgumentMarkdownDescriptor.php b/src/Symfony/Component/Console/Descriptor/Markdown/InputArgumentMarkdownDescriptor.php index cac884376db1e..f3f2917874427 100644 --- a/src/Symfony/Component/Console/Descriptor/Markdown/InputArgumentMarkdownDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Markdown/InputArgumentMarkdownDescriptor.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Descriptor\Markdown; use Symfony\Component\Console\Input\InputArgument; diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/InputDefinitionMarkdownDescriptor.php b/src/Symfony/Component/Console/Descriptor/Markdown/InputDefinitionMarkdownDescriptor.php index 36b3691ad359b..fe57f9c000f13 100644 --- a/src/Symfony/Component/Console/Descriptor/Markdown/InputDefinitionMarkdownDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Markdown/InputDefinitionMarkdownDescriptor.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Descriptor\Markdown; use Symfony\Component\Console\Input\InputDefinition; diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/InputOptionMarkdownDescriptor.php b/src/Symfony/Component/Console/Descriptor/Markdown/InputOptionMarkdownDescriptor.php index 84e2b751638c7..411c3e84e032f 100644 --- a/src/Symfony/Component/Console/Descriptor/Markdown/InputOptionMarkdownDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Markdown/InputOptionMarkdownDescriptor.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Descriptor\Markdown; use Symfony\Component\Console\Input\InputOption; diff --git a/src/Symfony/Component/Console/Helper/DescriptorHelper.php b/src/Symfony/Component/Console/Helper/DescriptorHelper.php index b3d1e93937cf1..e8fc7926fdee5 100644 --- a/src/Symfony/Component/Console/Helper/DescriptorHelper.php +++ b/src/Symfony/Component/Console/Helper/DescriptorHelper.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Helper; use Symfony\Component\Console\Descriptor\DescriptorProvider; diff --git a/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php index 870d2408483b6..45769a429b9ff 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Tests\Descriptor; use Symfony\Component\Console\Descriptor\DescriptorInterface; diff --git a/src/Symfony/Component/Console/Tests/Descriptor/Json/ApplicationJsonDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/Json/ApplicationJsonDescriptorTest.php index 948867cba3285..fc23056c8efb8 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/Json/ApplicationJsonDescriptorTest.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/Json/ApplicationJsonDescriptorTest.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Tests\Descriptor\Json; use Symfony\Component\Console\Descriptor\Json\ApplicationJsonDescriptor; diff --git a/src/Symfony/Component/Console/Tests/Descriptor/Json/CommandJsonDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/Json/CommandJsonDescriptorTest.php index d73eb15e38484..5ad11e3209fae 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/Json/CommandJsonDescriptorTest.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/Json/CommandJsonDescriptorTest.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Tests\Descriptor\Json; use Symfony\Component\Console\Descriptor\Json\CommandJsonDescriptor; diff --git a/src/Symfony/Component/Console/Tests/Descriptor/Json/InputArgumentJsonDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/Json/InputArgumentJsonDescriptorTest.php index 84926c5c6c4a7..7c44b844d2a7e 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/Json/InputArgumentJsonDescriptorTest.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/Json/InputArgumentJsonDescriptorTest.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Tests\Descriptor\Json; use Symfony\Component\Console\Descriptor\Json\InputArgumentJsonDescriptor; diff --git a/src/Symfony/Component/Console/Tests/Descriptor/Json/InputDefinitionJsonDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/Json/InputDefinitionJsonDescriptorTest.php index 7dd204ff6107c..24b93ebcdba4e 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/Json/InputDefinitionJsonDescriptorTest.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/Json/InputDefinitionJsonDescriptorTest.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Tests\Descriptor\Json; use Symfony\Component\Console\Descriptor\Json\InputDefinitionJsonDescriptor; diff --git a/src/Symfony/Component/Console/Tests/Descriptor/Json/InputOptionJsonDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/Json/InputOptionJsonDescriptorTest.php index 256a8e84195ac..d23ffc85e0534 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/Json/InputOptionJsonDescriptorTest.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/Json/InputOptionJsonDescriptorTest.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Tests\Descriptor\Json; use Symfony\Component\Console\Descriptor\Json\InputOptionJsonDescriptor; diff --git a/src/Symfony/Component/Console/Tests/Descriptor/Markdown/ApplicationMarkdownDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/Markdown/ApplicationMarkdownDescriptorTest.php index 3864547be425f..d2a0144293d69 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/Markdown/ApplicationMarkdownDescriptorTest.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/Markdown/ApplicationMarkdownDescriptorTest.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Tests\Descriptor\Json; use Symfony\Component\Console\Descriptor\Markdown\ApplicationMarkdownDescriptor; diff --git a/src/Symfony/Component/Console/Tests/Descriptor/Markdown/CommandMarkdownDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/Markdown/CommandMarkdownDescriptorTest.php index 41e69ba452331..e535df50e0d99 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/Markdown/CommandMarkdownDescriptorTest.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/Markdown/CommandMarkdownDescriptorTest.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Tests\Descriptor\Json; use Symfony\Component\Console\Descriptor\Markdown\CommandMarkdownDescriptor; diff --git a/src/Symfony/Component/Console/Tests/Descriptor/Markdown/Document/FormatterTest.php b/src/Symfony/Component/Console/Tests/Descriptor/Markdown/Document/FormatterTest.php index f6b7910f59482..d2bd8a69f2206 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/Markdown/Document/FormatterTest.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/Markdown/Document/FormatterTest.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Tests\Descriptor\Json\Document; use Symfony\Component\Console\Descriptor\Markdown\Document\Formatter; @@ -24,4 +33,4 @@ public function getClipTestData() array($lorem, 60, array($lorem)), ); } -} \ No newline at end of file +} diff --git a/src/Symfony/Component/Console/Tests/Descriptor/Markdown/InputArgumentMarkdownDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/Markdown/InputArgumentMarkdownDescriptorTest.php index 03d4fb4153600..7e762f7807b5f 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/Markdown/InputArgumentMarkdownDescriptorTest.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/Markdown/InputArgumentMarkdownDescriptorTest.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Tests\Descriptor\Json; use Symfony\Component\Console\Descriptor\Markdown\InputArgumentMarkdownDescriptor; diff --git a/src/Symfony/Component/Console/Tests/Descriptor/Markdown/InputDefinitionMarkdownDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/Markdown/InputDefinitionMarkdownDescriptorTest.php index 28e00c1d5ab9a..0faa4f56fd32a 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/Markdown/InputDefinitionMarkdownDescriptorTest.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/Markdown/InputDefinitionMarkdownDescriptorTest.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Tests\Descriptor\Json; use Symfony\Component\Console\Descriptor\Markdown\InputDefinitionMarkdownDescriptor; diff --git a/src/Symfony/Component/Console/Tests/Descriptor/Markdown/InputOptionMarkdownDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/Markdown/InputOptionMarkdownDescriptorTest.php index 272782f4d2ff4..216496c1a5a13 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/Markdown/InputOptionMarkdownDescriptorTest.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/Markdown/InputOptionMarkdownDescriptorTest.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Tests\Descriptor\Json; use Symfony\Component\Console\Descriptor\Markdown\InputOptionMarkdownDescriptor; diff --git a/src/Symfony/Component/Console/Tests/Descriptor/ObjectsProvider.php b/src/Symfony/Component/Console/Tests/Descriptor/ObjectsProvider.php index ee65da14c63fe..a36732174691a 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/ObjectsProvider.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/ObjectsProvider.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\Tests\Descriptor; use Symfony\Component\Console\Input\InputArgument; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplication1.php b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplication1.php index 6969b5806e567..132b6d57ddaa2 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplication1.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplication1.php @@ -1,5 +1,14 @@ + * + * 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\Application; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplication2.php b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplication2.php index 2f3f05ea80ffa..ff5513580041b 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplication2.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplication2.php @@ -1,5 +1,14 @@ + * + * 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\Application; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand1.php b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand1.php index 380a7229f9cf0..ede05d7a73c0f 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand1.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand1.php @@ -1,5 +1,14 @@ + * + * 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; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand2.php b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand2.php index f4c87c2cd4437..bc04ca9141272 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand2.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand2.php @@ -1,5 +1,14 @@ + * + * 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; From acc74140aa0366abbce18d0ebf231c6337a6357e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Wed, 3 Apr 2013 07:24:31 +0200 Subject: [PATCH 05/24] [Console] removed unused methods (tests broken) --- src/Symfony/Component/Console/Application.php | 104 -------------- .../Command/AbstractDescriptorCommand.php | 25 ++-- .../Component/Console/Command/Command.php | 74 ---------- .../Component/Console/Command/HelpCommand.php | 5 + .../Component/Console/Command/ListCommand.php | 4 + .../Console/Input/InputDefinition.php | 133 ------------------ .../Console/Tests/ApplicationTest.php | 18 --- .../Console/Tests/Command/CommandTest.php | 18 --- .../Tests/Fixtures/application_astext1.txt | 20 --- .../Tests/Fixtures/application_astext2.txt | 16 --- .../Tests/Fixtures/application_asxml1.txt | 128 ----------------- .../Tests/Fixtures/application_asxml2.txt | 37 ----- .../Console/Tests/Fixtures/command_astext.txt | 18 --- .../Console/Tests/Fixtures/command_asxml.txt | 38 ----- .../Tests/Fixtures/definition_astext.txt | 11 -- .../Tests/Fixtures/definition_asxml.txt | 39 ----- .../Tests/Input/InputDefinitionTest.php | 28 ---- 17 files changed, 22 insertions(+), 694 deletions(-) delete mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_astext1.txt delete mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_astext2.txt delete mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_asxml1.txt delete mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_asxml2.txt delete mode 100644 src/Symfony/Component/Console/Tests/Fixtures/command_astext.txt delete mode 100644 src/Symfony/Component/Console/Tests/Fixtures/command_asxml.txt delete mode 100644 src/Symfony/Component/Console/Tests/Fixtures/definition_astext.txt delete mode 100644 src/Symfony/Component/Console/Tests/Fixtures/definition_asxml.txt diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 4aec01637f883..245bf254878a7 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -680,110 +680,6 @@ public static function getAbbreviations($names) return $abbrevs; } - /** - * Returns a text representation of the Application. - * - * @param string $namespace An optional namespace name - * @param boolean $raw Whether to return raw command list - * - * @return string A string representing the Application - */ - public function asText($namespace = null, $raw = false) - { - $commands = $namespace ? $this->all($this->findNamespace($namespace)) : $this->commands; - - $width = 0; - foreach ($commands as $command) { - $width = strlen($command->getName()) > $width ? strlen($command->getName()) : $width; - } - $width += 2; - - if ($raw) { - $messages = array(); - foreach ($this->sortCommands($commands) as $space => $commands) { - foreach ($commands as $name => $command) { - $messages[] = sprintf("%-${width}s %s", $name, $command->getDescription()); - } - } - - return implode(PHP_EOL, $messages); - } - - $messages = array($this->getHelp(), ''); - if ($namespace) { - $messages[] = sprintf("Available commands for the \"%s\" namespace:", $namespace); - } else { - $messages[] = 'Available commands:'; - } - - // add commands by namespace - foreach ($this->sortCommands($commands) as $space => $commands) { - if (!$namespace && '_global' !== $space) { - $messages[] = ''.$space.''; - } - - foreach ($commands as $name => $command) { - $messages[] = sprintf(" %-${width}s %s", $name, $command->getDescription()); - } - } - - return implode(PHP_EOL, $messages); - } - - /** - * Returns an XML representation of the Application. - * - * @param string $namespace An optional namespace name - * @param Boolean $asDom Whether to return a DOM or an XML string - * - * @return string|DOMDocument An XML string representing the Application - */ - public function asXml($namespace = null, $asDom = false) - { - $commands = $namespace ? $this->all($this->findNamespace($namespace)) : $this->commands; - - $dom = new \DOMDocument('1.0', 'UTF-8'); - $dom->formatOutput = true; - $dom->appendChild($xml = $dom->createElement('symfony')); - - $xml->appendChild($commandsXML = $dom->createElement('commands')); - - if ($namespace) { - $commandsXML->setAttribute('namespace', $namespace); - } else { - $namespacesXML = $dom->createElement('namespaces'); - $xml->appendChild($namespacesXML); - } - - // add commands by namespace - foreach ($this->sortCommands($commands) as $space => $commands) { - if (!$namespace) { - $namespaceArrayXML = $dom->createElement('namespace'); - $namespacesXML->appendChild($namespaceArrayXML); - $namespaceArrayXML->setAttribute('id', $space); - } - - foreach ($commands as $name => $command) { - if ($name !== $command->getName()) { - continue; - } - - if (!$namespace) { - $commandXML = $dom->createElement('command'); - $namespaceArrayXML->appendChild($commandXML); - $commandXML->appendChild($dom->createTextNode($name)); - } - - $node = $command->asXml(true)->getElementsByTagName('command')->item(0); - $node = $dom->importNode($node, true); - - $commandsXML->appendChild($node); - } - } - - return $asDom ? $dom : $dom->saveXml(); - } - /** * Renders a caught exception. * diff --git a/src/Symfony/Component/Console/Command/AbstractDescriptorCommand.php b/src/Symfony/Component/Console/Command/AbstractDescriptorCommand.php index c3ccdf6e3bc78..d75a56e10ab5c 100644 --- a/src/Symfony/Component/Console/Command/AbstractDescriptorCommand.php +++ b/src/Symfony/Component/Console/Command/AbstractDescriptorCommand.php @@ -1,20 +1,13 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace Symfony\Component\Console\Command; use Symfony\Component\Console\Descriptor\DescriptorProvider; use Symfony\Component\Console\Helper\DescriptorHelper; use Symfony\Component\Console\Input\InputDefinition; +use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; /** * Base class for descriptor commands. @@ -33,10 +26,7 @@ abstract class AbstractDescriptorCommand extends Command */ protected function configure() { - $descriptorProvider = new DescriptorProvider(); - $this->supportedFormats = $descriptorProvider->getSupportedFormats(); $this->setDefinition($this->createDefinition()); - $this->getHelperSet()->set(new DescriptorHelper($descriptorProvider)); } /** @@ -51,4 +41,15 @@ protected function createDefinition() new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'), )); } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $descriptorProvider = new DescriptorProvider(); + $this->supportedFormats = $descriptorProvider->getSupportedFormats(); + $this->setDefinition($this->createDefinition()); + $this->getHelperSet()->set(new DescriptorHelper($descriptorProvider)); + } } diff --git a/src/Symfony/Component/Console/Command/Command.php b/src/Symfony/Component/Console/Command/Command.php index f475ad53632ab..870a65b548aff 100644 --- a/src/Symfony/Component/Console/Command/Command.php +++ b/src/Symfony/Component/Console/Command/Command.php @@ -555,80 +555,6 @@ public function getHelper($name) return $this->helperSet->get($name); } - /** - * Returns a text representation of the command. - * - * @return string A string representing the command - */ - public function asText() - { - if ($this->application && !$this->applicationDefinitionMerged) { - $this->getSynopsis(); - $this->mergeApplicationDefinition(false); - } - - $messages = array( - 'Usage:', - ' '.$this->getSynopsis(), - '', - ); - - if ($this->getAliases()) { - $messages[] = 'Aliases: '.implode(', ', $this->getAliases()).''; - } - - $messages[] = $this->getNativeDefinition()->asText(); - - if ($help = $this->getProcessedHelp()) { - $messages[] = 'Help:'; - $messages[] = ' '.str_replace("\n", "\n ", $help)."\n"; - } - - return implode("\n", $messages); - } - - /** - * Returns an XML representation of the command. - * - * @param Boolean $asDom Whether to return a DOM or an XML string - * - * @return string|DOMDocument An XML string representing the command - */ - public function asXml($asDom = false) - { - if ($this->application && !$this->applicationDefinitionMerged) { - $this->getSynopsis(); - $this->mergeApplicationDefinition(false); - } - - $dom = new \DOMDocument('1.0', 'UTF-8'); - $dom->formatOutput = true; - $dom->appendChild($commandXML = $dom->createElement('command')); - $commandXML->setAttribute('id', $this->name); - $commandXML->setAttribute('name', $this->name); - - $commandXML->appendChild($usageXML = $dom->createElement('usage')); - $usageXML->appendChild($dom->createTextNode(sprintf($this->getSynopsis(), ''))); - - $commandXML->appendChild($descriptionXML = $dom->createElement('description')); - $descriptionXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $this->getDescription()))); - - $commandXML->appendChild($helpXML = $dom->createElement('help')); - $helpXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $this->getProcessedHelp()))); - - $commandXML->appendChild($aliasesXML = $dom->createElement('aliases')); - foreach ($this->getAliases() as $alias) { - $aliasesXML->appendChild($aliasXML = $dom->createElement('alias')); - $aliasXML->appendChild($dom->createTextNode($alias)); - } - - $definition = $this->getNativeDefinition()->asXml(true); - $commandXML->appendChild($dom->importNode($definition->getElementsByTagName('arguments')->item(0), true)); - $commandXML->appendChild($dom->importNode($definition->getElementsByTagName('options')->item(0), true)); - - return $asDom ? $dom : $dom->saveXml(); - } - private function validateName($name) { if (!preg_match('/^[^\:]+(\:[^\:]+)*$/', $name)) { diff --git a/src/Symfony/Component/Console/Command/HelpCommand.php b/src/Symfony/Component/Console/Command/HelpCommand.php index b467e710bc028..748ed293180a7 100644 --- a/src/Symfony/Component/Console/Command/HelpCommand.php +++ b/src/Symfony/Component/Console/Command/HelpCommand.php @@ -30,6 +30,8 @@ class HelpCommand extends AbstractDescriptorCommand */ protected function configure() { + parent::configure(); + $this->ignoreValidationErrors(); $this @@ -66,6 +68,7 @@ public function setCommand(Command $command) protected function createDefinition() { $definition = parent::createDefinition(); + $definition->addArgument(new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help')); return $definition; @@ -76,6 +79,8 @@ protected function createDefinition() */ protected function execute(InputInterface $input, OutputInterface $output) { + parent::execute($input, $output); + if (null === $this->command) { $this->command = $this->getApplication()->find($input->getArgument('command_name')); } diff --git a/src/Symfony/Component/Console/Command/ListCommand.php b/src/Symfony/Component/Console/Command/ListCommand.php index e4c2f6025a63f..4b3bff7ce096e 100644 --- a/src/Symfony/Component/Console/Command/ListCommand.php +++ b/src/Symfony/Component/Console/Command/ListCommand.php @@ -28,6 +28,8 @@ class ListCommand extends AbstractDescriptorCommand */ protected function configure() { + parent::configure(); + $this ->setName('list') ->setDescription('Lists commands') @@ -76,6 +78,8 @@ protected function getNativeDefinition() */ protected function execute(InputInterface $input, OutputInterface $output) { + parent::execute($input, $output); + $this->getHelper('descriptor')->describe($output, $this->getApplication(), $input->getArgument('format'), $input->getOption('raw')); } } diff --git a/src/Symfony/Component/Console/Input/InputDefinition.php b/src/Symfony/Component/Console/Input/InputDefinition.php index 69d2f1efe125b..4c5dcf3b574dd 100644 --- a/src/Symfony/Component/Console/Input/InputDefinition.php +++ b/src/Symfony/Component/Console/Input/InputDefinition.php @@ -399,137 +399,4 @@ public function getSynopsis() return implode(' ', $elements); } - - /** - * Returns a textual representation of the InputDefinition. - * - * @return string A string representing the InputDefinition - */ - public function asText() - { - // find the largest option or argument name - $max = 0; - foreach ($this->getOptions() as $option) { - $nameLength = strlen($option->getName()) + 2; - if ($option->getShortcut()) { - $nameLength += strlen($option->getShortcut()) + 3; - } - - $max = max($max, $nameLength); - } - foreach ($this->getArguments() as $argument) { - $max = max($max, strlen($argument->getName())); - } - ++$max; - - $text = array(); - - if ($this->getArguments()) { - $text[] = 'Arguments:'; - foreach ($this->getArguments() as $argument) { - if (null !== $argument->getDefault() && (!is_array($argument->getDefault()) || count($argument->getDefault()))) { - $default = sprintf(' (default: %s)', $this->formatDefaultValue($argument->getDefault())); - } else { - $default = ''; - } - - $description = str_replace("\n", "\n".str_repeat(' ', $max + 2), $argument->getDescription()); - - $text[] = sprintf(" %-${max}s %s%s", $argument->getName(), $description, $default); - } - - $text[] = ''; - } - - if ($this->getOptions()) { - $text[] = 'Options:'; - - foreach ($this->getOptions() as $option) { - if ($option->acceptValue() && null !== $option->getDefault() && (!is_array($option->getDefault()) || count($option->getDefault()))) { - $default = sprintf(' (default: %s)', $this->formatDefaultValue($option->getDefault())); - } else { - $default = ''; - } - - $multiple = $option->isArray() ? ' (multiple values allowed)' : ''; - $description = str_replace("\n", "\n".str_repeat(' ', $max + 2), $option->getDescription()); - - $optionMax = $max - strlen($option->getName()) - 2; - $text[] = sprintf(" %s %-${optionMax}s%s%s%s", - '--'.$option->getName(), - $option->getShortcut() ? sprintf('(-%s) ', $option->getShortcut()) : '', - $description, - $default, - $multiple - ); - } - - $text[] = ''; - } - - return implode("\n", $text); - } - - /** - * Returns an XML representation of the InputDefinition. - * - * @param Boolean $asDom Whether to return a DOM or an XML string - * - * @return string|DOMDocument An XML string representing the InputDefinition - */ - public function asXml($asDom = false) - { - $dom = new \DOMDocument('1.0', 'UTF-8'); - $dom->formatOutput = true; - $dom->appendChild($definitionXML = $dom->createElement('definition')); - - $definitionXML->appendChild($argumentsXML = $dom->createElement('arguments')); - foreach ($this->getArguments() as $argument) { - $argumentsXML->appendChild($argumentXML = $dom->createElement('argument')); - $argumentXML->setAttribute('name', $argument->getName()); - $argumentXML->setAttribute('is_required', $argument->isRequired() ? 1 : 0); - $argumentXML->setAttribute('is_array', $argument->isArray() ? 1 : 0); - $argumentXML->appendChild($descriptionXML = $dom->createElement('description')); - $descriptionXML->appendChild($dom->createTextNode($argument->getDescription())); - - $argumentXML->appendChild($defaultsXML = $dom->createElement('defaults')); - $defaults = is_array($argument->getDefault()) ? $argument->getDefault() : (is_bool($argument->getDefault()) ? array(var_export($argument->getDefault(), true)) : ($argument->getDefault() ? array($argument->getDefault()) : array())); - foreach ($defaults as $default) { - $defaultsXML->appendChild($defaultXML = $dom->createElement('default')); - $defaultXML->appendChild($dom->createTextNode($default)); - } - } - - $definitionXML->appendChild($optionsXML = $dom->createElement('options')); - foreach ($this->getOptions() as $option) { - $optionsXML->appendChild($optionXML = $dom->createElement('option')); - $optionXML->setAttribute('name', '--'.$option->getName()); - $optionXML->setAttribute('shortcut', $option->getShortcut() ? '-'.$option->getShortcut() : ''); - $optionXML->setAttribute('accept_value', $option->acceptValue() ? 1 : 0); - $optionXML->setAttribute('is_value_required', $option->isValueRequired() ? 1 : 0); - $optionXML->setAttribute('is_multiple', $option->isArray() ? 1 : 0); - $optionXML->appendChild($descriptionXML = $dom->createElement('description')); - $descriptionXML->appendChild($dom->createTextNode($option->getDescription())); - - if ($option->acceptValue()) { - $optionXML->appendChild($defaultsXML = $dom->createElement('defaults')); - $defaults = is_array($option->getDefault()) ? $option->getDefault() : (is_bool($option->getDefault()) ? array(var_export($option->getDefault(), true)) : ($option->getDefault() ? array($option->getDefault()) : array())); - foreach ($defaults as $default) { - $defaultsXML->appendChild($defaultXML = $dom->createElement('default')); - $defaultXML->appendChild($dom->createTextNode($default)); - } - } - } - - return $asDom ? $dom : $dom->saveXml(); - } - - private function formatDefaultValue($default) - { - if (version_compare(PHP_VERSION, '5.4', '<')) { - return str_replace('\/', '/', json_encode($default)); - } - - return json_encode($default, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); - } } diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index f2614bfa37e26..783d364dc1d1a 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -392,24 +392,6 @@ public function testSetCatchExceptions() } } - public function testAsText() - { - $application = new Application(); - $application->add(new \FooCommand); - $this->ensureStaticCommandHelp($application); - $this->assertStringEqualsFile(self::$fixturesPath.'/application_astext1.txt', $this->normalizeLineBreaks($application->asText()), '->asText() returns a text representation of the application'); - $this->assertStringEqualsFile(self::$fixturesPath.'/application_astext2.txt', $this->normalizeLineBreaks($application->asText('foo')), '->asText() returns a text representation of the application'); - } - - public function testAsXml() - { - $application = new Application(); - $application->add(new \FooCommand); - $this->ensureStaticCommandHelp($application); - $this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/application_asxml1.txt', $application->asXml(), '->asXml() returns an XML representation of the application'); - $this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/application_asxml2.txt', $application->asXml('foo'), '->asXml() returns an XML representation of the application'); - } - public function testRenderException() { $application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth')); diff --git a/src/Symfony/Component/Console/Tests/Command/CommandTest.php b/src/Symfony/Component/Console/Tests/Command/CommandTest.php index acbe2ea10ce38..3aa990f9be083 100644 --- a/src/Symfony/Component/Console/Tests/Command/CommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/CommandTest.php @@ -280,22 +280,4 @@ public function callableMethodCommand(InputInterface $input, OutputInterface $ou { $output->writeln('from the code...'); } - - public function testAsText() - { - $command = new \TestCommand(); - $command->setApplication(new Application()); - $tester = new CommandTester($command); - $tester->execute(array('command' => $command->getName())); - $this->assertStringEqualsFile(self::$fixturesPath.'/command_astext.txt', $command->asText(), '->asText() returns a text representation of the command'); - } - - public function testAsXml() - { - $command = new \TestCommand(); - $command->setApplication(new Application()); - $tester = new CommandTester($command); - $tester->execute(array('command' => $command->getName())); - $this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/command_asxml.txt', $command->asXml(), '->asXml() returns an XML representation of the command'); - } } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_astext1.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_astext1.txt deleted file mode 100644 index 2f692c07e0a8f..0000000000000 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_astext1.txt +++ /dev/null @@ -1,20 +0,0 @@ -Console Tool - -Usage: - [options] command [arguments] - -Options: - --help -h Display this help message. - --quiet -q Do not output any message. - --verbose -v Increase verbosity of messages. - --version -V Display this application version. - --ansi Force ANSI output. - --no-ansi Disable ANSI output. - --no-interaction -n Do not ask any interactive question. - -Available commands: - afoobar The foo:bar command - help Displays help for a command - list Lists commands -foo - foo:bar The foo:bar command \ No newline at end of file diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_astext2.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_astext2.txt deleted file mode 100644 index 1457bf793d6c1..0000000000000 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_astext2.txt +++ /dev/null @@ -1,16 +0,0 @@ -Console Tool - -Usage: - [options] command [arguments] - -Options: - --help -h Display this help message. - --quiet -q Do not output any message. - --verbose -v Increase verbosity of messages. - --version -V Display this application version. - --ansi Force ANSI output. - --no-ansi Disable ANSI output. - --no-interaction -n Do not ask any interactive question. - -Available commands for the "foo" namespace: - foo:bar The foo:bar command \ No newline at end of file diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_asxml1.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_asxml1.txt deleted file mode 100644 index ed168f25cbcda..0000000000000 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_asxml1.txt +++ /dev/null @@ -1,128 +0,0 @@ - - - - - help [--xml] [command_name] - Displays help for a command - The <info>help</info> command displays help for a given command: - - <info>php app/console help list</info> - - You can also output the help as XML by using the <comment>--xml</comment> option: - - <info>php app/console help --xml list</info> - - To display the list of available commands, please use the <info>list</info> command. - - - - The command name - - help - - - - - - - - - - - - - - - - list [--xml] [--raw] [namespace] - Lists commands - The <info>list</info> command lists all commands: - - <info>php app/console list</info> - - You can also display the commands for a specific namespace: - - <info>php app/console list test</info> - - You can also output the information as XML by using the <comment>--xml</comment> option: - - <info>php app/console list --xml</info> - - It's also possible to get raw list of commands (useful for embedding command runner): - - <info>php app/console list --raw</info> - - - - The namespace name - - - - - - - - - - foo:bar - The foo:bar command - - - afoobar - - - - - - - - - - - - - - - - help - list - - - foo:bar - - - diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_asxml2.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_asxml2.txt deleted file mode 100644 index ef92f85cbfe07..0000000000000 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_asxml2.txt +++ /dev/null @@ -1,37 +0,0 @@ - - - - - foo:bar - The foo:bar command - - - afoobar - - - - - - - - - - - - - - diff --git a/src/Symfony/Component/Console/Tests/Fixtures/command_astext.txt b/src/Symfony/Component/Console/Tests/Fixtures/command_astext.txt deleted file mode 100644 index e5999030e3679..0000000000000 --- a/src/Symfony/Component/Console/Tests/Fixtures/command_astext.txt +++ /dev/null @@ -1,18 +0,0 @@ -Usage: - namespace:name - -Aliases: name -Arguments: - command The command to execute - -Options: - --help (-h) Display this help message. - --quiet (-q) Do not output any message. - --verbose (-v) Increase verbosity of messages. - --version (-V) Display this application version. - --ansi Force ANSI output. - --no-ansi Disable ANSI output. - --no-interaction (-n) Do not ask any interactive question. - -Help: - help diff --git a/src/Symfony/Component/Console/Tests/Fixtures/command_asxml.txt b/src/Symfony/Component/Console/Tests/Fixtures/command_asxml.txt deleted file mode 100644 index 806c5a567089a..0000000000000 --- a/src/Symfony/Component/Console/Tests/Fixtures/command_asxml.txt +++ /dev/null @@ -1,38 +0,0 @@ - - - namespace:name - description - help - - name - - - - The command to execute - - - - - - - - - - - - - diff --git a/src/Symfony/Component/Console/Tests/Fixtures/definition_astext.txt b/src/Symfony/Component/Console/Tests/Fixtures/definition_astext.txt deleted file mode 100644 index a7d7e0d5134ec..0000000000000 --- a/src/Symfony/Component/Console/Tests/Fixtures/definition_astext.txt +++ /dev/null @@ -1,11 +0,0 @@ -Arguments: - foo The foo argument - baz The baz argument (default: true) - bar The bar argument (default: ["http://foo.com/"]) - -Options: - --foo (-f) The foo option - --baz The baz option (default: false) - --bar (-b) The bar option (default: "bar") - --qux The qux option (default: ["http://foo.com/","bar"]) (multiple values allowed) - --qux2 The qux2 option (default: {"foo":"bar"}) (multiple values allowed) diff --git a/src/Symfony/Component/Console/Tests/Fixtures/definition_asxml.txt b/src/Symfony/Component/Console/Tests/Fixtures/definition_asxml.txt deleted file mode 100644 index eec8c079ee3ee..0000000000000 --- a/src/Symfony/Component/Console/Tests/Fixtures/definition_asxml.txt +++ /dev/null @@ -1,39 +0,0 @@ - - - - - The foo argument - - - - The baz argument - - true - - - - The bar argument - - bar - - - - - - - - - diff --git a/src/Symfony/Component/Console/Tests/Input/InputDefinitionTest.php b/src/Symfony/Component/Console/Tests/Input/InputDefinitionTest.php index 76316bd863f68..dd4a57ba847c8 100644 --- a/src/Symfony/Component/Console/Tests/Input/InputDefinitionTest.php +++ b/src/Symfony/Component/Console/Tests/Input/InputDefinitionTest.php @@ -364,34 +364,6 @@ public function testGetSynopsis() $this->assertEquals('foo1 ... [fooN]', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options'); } - public function testAsText() - { - $definition = new InputDefinition(array( - new InputArgument('foo', InputArgument::OPTIONAL, 'The foo argument'), - new InputArgument('baz', InputArgument::OPTIONAL, 'The baz argument', true), - new InputArgument('bar', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'The bar argument', array('http://foo.com/')), - new InputOption('foo', 'f', InputOption::VALUE_REQUIRED, 'The foo option'), - new InputOption('baz', null, InputOption::VALUE_OPTIONAL, 'The baz option', false), - new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL, 'The bar option', 'bar'), - new InputOption('qux', '', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The qux option', array('http://foo.com/', 'bar')), - new InputOption('qux2', '', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The qux2 option', array('foo' => 'bar')), - )); - $this->assertStringEqualsFile(self::$fixtures.'/definition_astext.txt', $definition->asText(), '->asText() returns a textual representation of the InputDefinition'); - } - - public function testAsXml() - { - $definition = new InputDefinition(array( - new InputArgument('foo', InputArgument::OPTIONAL, 'The foo argument'), - new InputArgument('baz', InputArgument::OPTIONAL, 'The baz argument', true), - new InputArgument('bar', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'The bar argument', array('bar')), - new InputOption('foo', 'f', InputOption::VALUE_REQUIRED, 'The foo option'), - new InputOption('baz', null, InputOption::VALUE_OPTIONAL, 'The baz option', false), - new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL, 'The bar option', 'bar'), - )); - $this->assertXmlStringEqualsXmlFile(self::$fixtures.'/definition_asxml.txt', $definition->asXml(), '->asText() returns a textual representation of the InputDefinition'); - } - protected function initializeArguments() { $this->foo = new InputArgument('foo'); From 774794c6ae08a86ef6af19bb35220d5245517349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Wed, 3 Apr 2013 16:39:53 +0200 Subject: [PATCH 06/24] [Console] fixed tests --- .../Command/AbstractDescriptorCommand.php | 12 ++-- .../Component/Console/Command/HelpCommand.php | 4 +- .../Component/Console/Command/ListCommand.php | 2 +- .../Console/Descriptor/DescriptorProvider.php | 13 +++- .../Console/Tests/Command/HelpCommandTest.php | 16 ++--- .../Console/Tests/Command/ListCommandTest.php | 3 +- .../Console/Tests/Fixtures/application_1.json | 2 +- .../Console/Tests/Fixtures/application_1.md | 68 ++++++++++++++++++- .../Console/Tests/Fixtures/application_2.json | 2 +- .../Console/Tests/Fixtures/application_2.md | 68 ++++++++++++++++++- .../Fixtures/application_renderexception2.txt | 2 +- 11 files changed, 160 insertions(+), 32 deletions(-) diff --git a/src/Symfony/Component/Console/Command/AbstractDescriptorCommand.php b/src/Symfony/Component/Console/Command/AbstractDescriptorCommand.php index d75a56e10ab5c..2df8133d630c2 100644 --- a/src/Symfony/Component/Console/Command/AbstractDescriptorCommand.php +++ b/src/Symfony/Component/Console/Command/AbstractDescriptorCommand.php @@ -17,15 +17,16 @@ abstract class AbstractDescriptorCommand extends Command { /** - * @var array + * @var DescriptorProvider */ - private $supportedFormats; + private $provider; /** * {@inheritdoc} */ protected function configure() { + $this->provider = new DescriptorProvider(); $this->setDefinition($this->createDefinition()); } @@ -37,7 +38,7 @@ protected function configure() protected function createDefinition() { return new InputDefinition(array( - new InputOption('format', null, InputOption::VALUE_OPTIONAL, 'Output format ('.implode(', ', $this->supportedFormats).')'), + new InputOption('format', null, InputOption::VALUE_OPTIONAL, 'Output format ('.implode(', ', $this->provider->getSupportedFormats()).')'), new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'), )); } @@ -47,9 +48,6 @@ protected function createDefinition() */ protected function execute(InputInterface $input, OutputInterface $output) { - $descriptorProvider = new DescriptorProvider(); - $this->supportedFormats = $descriptorProvider->getSupportedFormats(); - $this->setDefinition($this->createDefinition()); - $this->getHelperSet()->set(new DescriptorHelper($descriptorProvider)); + $this->getHelperSet()->set(new DescriptorHelper($this->provider)); } } diff --git a/src/Symfony/Component/Console/Command/HelpCommand.php b/src/Symfony/Component/Console/Command/HelpCommand.php index 748ed293180a7..94a70721cc74d 100644 --- a/src/Symfony/Component/Console/Command/HelpCommand.php +++ b/src/Symfony/Component/Console/Command/HelpCommand.php @@ -31,7 +31,6 @@ class HelpCommand extends AbstractDescriptorCommand protected function configure() { parent::configure(); - $this->ignoreValidationErrors(); $this @@ -68,7 +67,6 @@ public function setCommand(Command $command) protected function createDefinition() { $definition = parent::createDefinition(); - $definition->addArgument(new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help')); return $definition; @@ -85,7 +83,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->command = $this->getApplication()->find($input->getArgument('command_name')); } - $this->getHelper('descriptor')->describe($output, $this->command, $input->getArgument('format'), $input->getOption('raw')); + $this->getHelper('descriptor')->describe($output, $this->command, $input->getOption('format'), $input->getOption('raw')); $this->command = null; } diff --git a/src/Symfony/Component/Console/Command/ListCommand.php b/src/Symfony/Component/Console/Command/ListCommand.php index 4b3bff7ce096e..8b75dd05ae289 100644 --- a/src/Symfony/Component/Console/Command/ListCommand.php +++ b/src/Symfony/Component/Console/Command/ListCommand.php @@ -80,6 +80,6 @@ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); - $this->getHelper('descriptor')->describe($output, $this->getApplication(), $input->getArgument('format'), $input->getOption('raw')); + $this->getHelper('descriptor')->describe($output, $this->getApplication(), $input->getOption('format'), $input->getOption('raw')); } } diff --git a/src/Symfony/Component/Console/Descriptor/DescriptorProvider.php b/src/Symfony/Component/Console/Descriptor/DescriptorProvider.php index ca8b835ac51b6..73d2228ea1ed9 100644 --- a/src/Symfony/Component/Console/Descriptor/DescriptorProvider.php +++ b/src/Symfony/Component/Console/Descriptor/DescriptorProvider.php @@ -28,8 +28,9 @@ class DescriptorProvider */ private $options = array( 'default_format' => 'txt', - 'json_encoding' => 0, 'namespace' => null, + 'json_encoding' => 0, + 'markdown_width' => 120, ); /** @@ -46,6 +47,11 @@ public function __construct(array $options = array()) ->add(new Json\InputDefinitionJsonDescriptor()) ->add(new Json\InputArgumentJsonDescriptor()) ->add(new Json\InputOptionJsonDescriptor()) + ->add(new Markdown\ApplicationMarkdownDescriptor()) + ->add(new Markdown\CommandMarkdownDescriptor()) + ->add(new Markdown\InputDefinitionMarkdownDescriptor()) + ->add(new Markdown\InputArgumentMarkdownDescriptor()) + ->add(new Markdown\InputOptionMarkdownDescriptor()) ; } @@ -125,6 +131,9 @@ public function getSupportedFormats() $supportedFormats[] = $descriptor->getFormat(); } - return array_unique($supportedFormats); + $supportedFormats = array_unique($supportedFormats); + sort($supportedFormats); + + return $supportedFormats; } } diff --git a/src/Symfony/Component/Console/Tests/Command/HelpCommandTest.php b/src/Symfony/Component/Console/Tests/Command/HelpCommandTest.php index f9b72e6ae385e..c55c4ca03dbd0 100644 --- a/src/Symfony/Component/Console/Tests/Command/HelpCommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/HelpCommandTest.php @@ -24,8 +24,7 @@ public function testExecuteForCommandAlias() $command->setApplication(new Application()); $commandTester = new CommandTester($command); $commandTester->execute(array('command_name' => 'li')); - - $this->assertRegExp('/list \[--xml\] \[--raw\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command alias'); + $this->assertRegExp('/list \[--format="\.\.\."\] \[--raw\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command alias'); } public function testExecuteForCommand() @@ -34,8 +33,7 @@ public function testExecuteForCommand() $commandTester = new CommandTester($command); $command->setCommand(new ListCommand()); $commandTester->execute(array()); - - $this->assertRegExp('/list \[--xml\] \[--raw\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); + $this->assertRegExp('/list \[--format="\.\.\."\] \[--raw\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); } public function testExecuteForCommandWithXmlOption() @@ -43,8 +41,7 @@ public function testExecuteForCommandWithXmlOption() $command = new HelpCommand(); $commandTester = new CommandTester($command); $command->setCommand(new ListCommand()); - $commandTester->execute(array('--xml' => true)); - + $commandTester->execute(array('--format' => 'xml')); $this->assertRegExp('/getDisplay(), '->execute() returns an XML help text if --xml is passed'); } @@ -53,16 +50,15 @@ public function testExecuteForApplicationCommand() $application = new Application(); $commandTester = new CommandTester($application->get('help')); $commandTester->execute(array('command_name' => 'list')); - - $this->assertRegExp('/list \[--xml\] \[--raw\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); + $this->assertRegExp('/list \[--format="\.\.\."\] \[--raw\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); } public function testExecuteForApplicationCommandWithXmlOption() { $application = new Application(); $commandTester = new CommandTester($application->get('help')); - $commandTester->execute(array('command_name' => 'list', '--xml' => true)); - + $commandTester->execute(array('command_name' => 'list', 'format' => 'xml')); + $this->assertRegExp('/list \[--format="\.\.\."\] \[--raw\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); $this->assertRegExp('/getDisplay(), '->execute() returns an XML help text if --xml is passed'); } } diff --git a/src/Symfony/Component/Console/Tests/Command/ListCommandTest.php b/src/Symfony/Component/Console/Tests/Command/ListCommandTest.php index cad313652c0aa..156e21db470d8 100644 --- a/src/Symfony/Component/Console/Tests/Command/ListCommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/ListCommandTest.php @@ -29,8 +29,7 @@ public function testExecuteListsCommandsWithXmlOption() { $application = new Application(); $commandTester = new CommandTester($command = $application->get('list')); - $commandTester->execute(array('command' => $command->getName(), '--xml' => true)); - + $commandTester->execute(array('command' => $command->getName(), '--format' => 'xml')); $this->assertRegExp('//', $commandTester->getDisplay(), '->execute() returns a list of available commands in XML if --xml is passed'); } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.json b/src/Symfony/Component/Console/Tests/Fixtures/application_1.json index 888d127f7b7de..9f3d2820cd2b4 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_1.json +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.json @@ -1 +1 @@ -{"commands":[{"name":"help","usage":"help","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php \/usr\/bin\/phpunit help list<\/info>\n\nYou can also output the help as XML by using the --xml<\/comment> option:\n\n php \/usr\/bin\/phpunit help --xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":[],"options":[]}},{"name":"list","usage":"list","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php \/usr\/bin\/phpunit list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php \/usr\/bin\/phpunit list test<\/info>\n\nYou can also output the information as XML by using the --xml<\/comment> option:\n\n php \/usr\/bin\/phpunit list --xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php \/usr\/bin\/phpunit list --raw<\/info>","aliases":[],"definition":{"arguments":[],"options":[]}}],"namespaces":[{"id":"_global","commands":["help","list"]}]} +{"commands":[{"name":"help","usage":"help [--format[=\"...\"]] [--raw] [command_name]","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php \/usr\/bin\/phpunit help list<\/info>\n\nYou can also output the help as XML by using the --xml<\/comment> option:\n\n php \/usr\/bin\/phpunit help --xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":false,"is_multiple":false,"description":"Output format (json, md)","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false}}}},{"name":"list","usage":"list [--format[=\"...\"]] [--raw] [namespace]","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php \/usr\/bin\/phpunit list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php \/usr\/bin\/phpunit list test<\/info>\n\nYou can also output the information as XML by using the --xml<\/comment> option:\n\n php \/usr\/bin\/phpunit list --xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php \/usr\/bin\/phpunit list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":false,"is_multiple":false,"description":"Output format (json, md)","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false}}}}],"namespaces":[{"id":"_global","commands":["help","list"]}]} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.md b/src/Symfony/Component/Console/Tests/Fixtures/application_1.md index 8a66309fd4fb4..bb0ce0371d7d4 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_1.md +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.md @@ -8,7 +8,7 @@ help ---- * Description: Displays help for a command -* Usage: `help` +* Usage: `help [--format[="..."]] [--raw] [command_name]` * Aliases: The help command displays help for a given command: @@ -21,11 +21,43 @@ You can also output the help as XML by using the --xml option To display the list of available commands, please use the list command. +### Arguments: + +**command_name:** + +* Name: command_name +* Is required: no +* Is array: no +* Description: The command name +* Default: `'help'` + +### Options: + +**format:** + +* Name: `--format` +* Shortcut: +* Accept value: yes +* Is value required: no +* Is multiple: no +* Description: Output format (json, md) +* Default: `NULL` + +**raw:** + +* Name: `--raw` +* Shortcut: +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: To output raw command list +* Default: `false` + list ---- * Description: Lists commands -* Usage: `list` +* Usage: `list [--format[="..."]] [--raw] [namespace]` * Aliases: The list command lists all commands: @@ -43,3 +75,35 @@ You can also output the information as XML by using the --xml It's also possible to get raw list of commands (useful for embedding command runner): php /usr/bin/phpunit list --raw + +### Arguments: + +**namespace:** + +* Name: namespace +* Is required: no +* Is array: no +* Description: The namespace name +* Default: `NULL` + +### Options: + +**format:** + +* Name: `--format` +* Shortcut: +* Accept value: yes +* Is value required: no +* Is multiple: no +* Description: Output format (json, md) +* Default: `NULL` + +**raw:** + +* Name: `--raw` +* Shortcut: +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: To output raw command list +* Default: `false` diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.json b/src/Symfony/Component/Console/Tests/Fixtures/application_2.json index 0176a6221140b..5871aef56d84a 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_2.json +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.json @@ -1 +1 @@ -{"commands":[{"name":"help","usage":"help","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php \/usr\/bin\/phpunit help list<\/info>\n\nYou can also output the help as XML by using the --xml<\/comment> option:\n\n php \/usr\/bin\/phpunit help --xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":[],"options":[]}},{"name":"list","usage":"list","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php \/usr\/bin\/phpunit list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php \/usr\/bin\/phpunit list test<\/info>\n\nYou can also output the information as XML by using the --xml<\/comment> option:\n\n php \/usr\/bin\/phpunit list --xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php \/usr\/bin\/phpunit list --raw<\/info>","aliases":[],"definition":{"arguments":[],"options":[]}},{"name":"descriptor:command1","usage":"descriptor:command1","description":"command 1 description","help":"command 1 help","aliases":["alias1","alias2"],"definition":{"arguments":[],"options":[]}},{"name":"descriptor:command2","usage":"descriptor:command2 [-o|--option_name] argument_name","description":"command 2 description","help":"command 2 help","aliases":[],"definition":{"arguments":{"argument_name":{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null}},"options":{"option_name":{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false}}}}],"namespaces":[{"id":"_global","commands":["alias1","alias2","help","list"]},{"id":"descriptor","commands":["descriptor:command1","descriptor:command2"]}]} +{"commands":[{"name":"help","usage":"help [--format[=\"...\"]] [--raw] [command_name]","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php \/usr\/bin\/phpunit help list<\/info>\n\nYou can also output the help as XML by using the --xml<\/comment> option:\n\n php \/usr\/bin\/phpunit help --xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":false,"is_multiple":false,"description":"Output format (json, md)","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false}}}},{"name":"list","usage":"list [--format[=\"...\"]] [--raw] [namespace]","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php \/usr\/bin\/phpunit list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php \/usr\/bin\/phpunit list test<\/info>\n\nYou can also output the information as XML by using the --xml<\/comment> option:\n\n php \/usr\/bin\/phpunit list --xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php \/usr\/bin\/phpunit list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":false,"is_multiple":false,"description":"Output format (json, md)","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false}}}},{"name":"descriptor:command1","usage":"descriptor:command1","description":"command 1 description","help":"command 1 help","aliases":["alias1","alias2"],"definition":{"arguments":[],"options":[]}},{"name":"descriptor:command2","usage":"descriptor:command2 [-o|--option_name] argument_name","description":"command 2 description","help":"command 2 help","aliases":[],"definition":{"arguments":{"argument_name":{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null}},"options":{"option_name":{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false}}}}],"namespaces":[{"id":"_global","commands":["alias1","alias2","help","list"]},{"id":"descriptor","commands":["descriptor:command1","descriptor:command2"]}]} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.md b/src/Symfony/Component/Console/Tests/Fixtures/application_2.md index baa59dfcdc867..d06a11c842979 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_2.md +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.md @@ -15,7 +15,7 @@ help ---- * Description: Displays help for a command -* Usage: `help` +* Usage: `help [--format[="..."]] [--raw] [command_name]` * Aliases: The help command displays help for a given command: @@ -28,11 +28,43 @@ You can also output the help as XML by using the --xml option To display the list of available commands, please use the list command. +### Arguments: + +**command_name:** + +* Name: command_name +* Is required: no +* Is array: no +* Description: The command name +* Default: `'help'` + +### Options: + +**format:** + +* Name: `--format` +* Shortcut: +* Accept value: yes +* Is value required: no +* Is multiple: no +* Description: Output format (json, md) +* Default: `NULL` + +**raw:** + +* Name: `--raw` +* Shortcut: +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: To output raw command list +* Default: `false` + list ---- * Description: Lists commands -* Usage: `list` +* Usage: `list [--format[="..."]] [--raw] [namespace]` * Aliases: The list command lists all commands: @@ -51,6 +83,38 @@ It's also possible to get raw list of commands (useful for embedding command run php /usr/bin/phpunit list --raw +### Arguments: + +**namespace:** + +* Name: namespace +* Is required: no +* Is array: no +* Description: The namespace name +* Default: `NULL` + +### Options: + +**format:** + +* Name: `--format` +* Shortcut: +* Accept value: yes +* Is value required: no +* Is multiple: no +* Description: Output format (json, md) +* Default: `NULL` + +**raw:** + +* Name: `--raw` +* Shortcut: +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: To output raw command list +* Default: `false` + descriptor:command1 ------------------- diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt index 56dd52ecbe8f3..068306a24fd3c 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt @@ -6,6 +6,6 @@ -list [--xml] [--raw] [namespace] +list [--format[="..."]] [--raw] [namespace] From 2066a9be21d70788100c8b2d4cf05250953bcfab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Sat, 6 Apr 2013 09:47:49 +0200 Subject: [PATCH 07/24] [Console] added XML descriptors --- ...and.php => AbstractDescriptionCommand.php} | 6 +- .../Component/Console/Command/HelpCommand.php | 10 +- .../Component/Console/Command/ListCommand.php | 6 +- .../Json/AbstractJsonDescriptor.php | 4 +- .../Json/ApplicationJsonDescriptor.php | 4 +- .../Markdown/AbstractMarkdownDescriptor.php | 4 +- .../ApplicationMarkdownDescriptor.php | 4 +- .../Descriptor/Xml/AbstractXmlDescriptor.php | 64 ++++++++++ .../Xml/ApplicationXmlDescriptor.php | 91 +++++++++++++++ .../Descriptor/Xml/CommandXmlDescriptor.php | 59 ++++++++++ .../Xml/InputArgumentXmlDescriptor.php | 51 ++++++++ .../Xml/InputDefinitionXmlDescriptor.php | 54 +++++++++ .../Xml/InputOptionXmlDescriptor.php | 58 ++++++++++ .../Descriptor/AbstractDescriptorTest.php | 17 +++ .../Xml/ApplicationXmlDescriptorTest.php | 29 +++++ .../Xml/CommandXmlDescriptorTest.php | 29 +++++ .../Xml/InputArgumentXmlDescriptorTest.php | 29 +++++ .../Xml/InputDefinitionXmlDescriptorTest.php | 29 +++++ .../Xml/InputOptionXmlDescriptorTest.php | 29 +++++ .../Console/Tests/Fixtures/application_1.json | 2 +- .../Console/Tests/Fixtures/application_1.md | 28 ++--- .../Console/Tests/Fixtures/application_1.xml | 75 ++++++++++++ .../Console/Tests/Fixtures/application_1.xml~ | 75 ++++++++++++ .../Console/Tests/Fixtures/application_2.json | 2 +- .../Console/Tests/Fixtures/application_2.md | 28 ++--- .../Console/Tests/Fixtures/application_2.xml | 109 ++++++++++++++++++ .../Console/Tests/Fixtures/application_2.xml~ | 109 ++++++++++++++++++ .../Fixtures/application_renderexception2.txt | 2 +- .../application_renderexception2.txt~ | 11 ++ .../Tests/Fixtures/application_run2.txt | 14 +-- .../Tests/Fixtures/application_run3.txt | 20 ++-- .../Console/Tests/Fixtures/command_1.xml | 12 ++ .../Console/Tests/Fixtures/command_2.xml | 18 +++ .../Tests/Fixtures/input_argument_1.xml | 5 + .../Tests/Fixtures/input_argument_2.xml | 5 + .../Tests/Fixtures/input_argument_3.xml | 7 ++ .../Tests/Fixtures/input_definition_1.xml | 5 + .../Tests/Fixtures/input_definition_2.xml | 10 ++ .../Tests/Fixtures/input_definition_3.xml | 9 ++ .../Tests/Fixtures/input_definition_4.xml | 14 +++ .../Console/Tests/Fixtures/input_option_1.xml | 4 + .../Console/Tests/Fixtures/input_option_2.xml | 7 ++ .../Console/Tests/Fixtures/input_option_3.xml | 4 + .../Console/Tests/Fixtures/input_option_4.xml | 4 + 44 files changed, 1092 insertions(+), 64 deletions(-) rename src/Symfony/Component/Console/Command/{AbstractDescriptorCommand.php => AbstractDescriptionCommand.php} (83%) create mode 100644 src/Symfony/Component/Console/Descriptor/Xml/AbstractXmlDescriptor.php create mode 100644 src/Symfony/Component/Console/Descriptor/Xml/ApplicationXmlDescriptor.php create mode 100644 src/Symfony/Component/Console/Descriptor/Xml/CommandXmlDescriptor.php create mode 100644 src/Symfony/Component/Console/Descriptor/Xml/InputArgumentXmlDescriptor.php create mode 100644 src/Symfony/Component/Console/Descriptor/Xml/InputDefinitionXmlDescriptor.php create mode 100644 src/Symfony/Component/Console/Descriptor/Xml/InputOptionXmlDescriptor.php create mode 100644 src/Symfony/Component/Console/Tests/Descriptor/Xml/ApplicationXmlDescriptorTest.php create mode 100644 src/Symfony/Component/Console/Tests/Descriptor/Xml/CommandXmlDescriptorTest.php create mode 100644 src/Symfony/Component/Console/Tests/Descriptor/Xml/InputArgumentXmlDescriptorTest.php create mode 100644 src/Symfony/Component/Console/Tests/Descriptor/Xml/InputDefinitionXmlDescriptorTest.php create mode 100644 src/Symfony/Component/Console/Tests/Descriptor/Xml/InputOptionXmlDescriptorTest.php create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_1.xml create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_1.xml~ create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_2.xml create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_2.xml~ create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt~ create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/command_1.xml create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/command_2.xml create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_argument_1.xml create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_argument_2.xml create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_argument_3.xml create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_definition_1.xml create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_definition_2.xml create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_definition_3.xml create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_definition_4.xml create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_1.xml create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_2.xml create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_3.xml create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_4.xml diff --git a/src/Symfony/Component/Console/Command/AbstractDescriptorCommand.php b/src/Symfony/Component/Console/Command/AbstractDescriptionCommand.php similarity index 83% rename from src/Symfony/Component/Console/Command/AbstractDescriptorCommand.php rename to src/Symfony/Component/Console/Command/AbstractDescriptionCommand.php index 2df8133d630c2..52d716da5af90 100644 --- a/src/Symfony/Component/Console/Command/AbstractDescriptorCommand.php +++ b/src/Symfony/Component/Console/Command/AbstractDescriptionCommand.php @@ -10,11 +10,11 @@ use Symfony\Component\Console\Output\OutputInterface; /** - * Base class for descriptor commands. + * Base class for description commands. * * @author Jean-François Simon */ -abstract class AbstractDescriptorCommand extends Command +abstract class AbstractDescriptionCommand extends Command { /** * @var DescriptorProvider @@ -38,7 +38,7 @@ protected function configure() protected function createDefinition() { return new InputDefinition(array( - new InputOption('format', null, InputOption::VALUE_OPTIONAL, 'Output format ('.implode(', ', $this->provider->getSupportedFormats()).')'), + new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output help in other formats'), new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'), )); } diff --git a/src/Symfony/Component/Console/Command/HelpCommand.php b/src/Symfony/Component/Console/Command/HelpCommand.php index 94a70721cc74d..3623b0241f0b6 100644 --- a/src/Symfony/Component/Console/Command/HelpCommand.php +++ b/src/Symfony/Component/Console/Command/HelpCommand.php @@ -21,7 +21,7 @@ * * @author Fabien Potencier */ -class HelpCommand extends AbstractDescriptorCommand +class HelpCommand extends AbstractDescriptionCommand { private $command; @@ -41,9 +41,9 @@ protected function configure() php %command.full_name% list -You can also output the help as XML by using the --xml option: +You can also output the help in other formats by using the --format option: - php %command.full_name% --xml list + php %command.full_name% --format=xml list To display the list of available commands, please use the list command. EOF @@ -77,14 +77,12 @@ protected function createDefinition() */ protected function execute(InputInterface $input, OutputInterface $output) { - parent::execute($input, $output); - if (null === $this->command) { $this->command = $this->getApplication()->find($input->getArgument('command_name')); } + parent::execute($input, $output); $this->getHelper('descriptor')->describe($output, $this->command, $input->getOption('format'), $input->getOption('raw')); - $this->command = null; } } diff --git a/src/Symfony/Component/Console/Command/ListCommand.php b/src/Symfony/Component/Console/Command/ListCommand.php index 8b75dd05ae289..7c6176d029c68 100644 --- a/src/Symfony/Component/Console/Command/ListCommand.php +++ b/src/Symfony/Component/Console/Command/ListCommand.php @@ -21,7 +21,7 @@ * * @author Fabien Potencier */ -class ListCommand extends AbstractDescriptorCommand +class ListCommand extends AbstractDescriptionCommand { /** * {@inheritdoc} @@ -42,9 +42,9 @@ protected function configure() php %command.full_name% test -You can also output the information as XML by using the --xml option: +You can also output the information in other formats by using the --format option: - php %command.full_name% --xml + php %command.full_name% --format=xml It's also possible to get raw list of commands (useful for embedding command runner): diff --git a/src/Symfony/Component/Console/Descriptor/Json/AbstractJsonDescriptor.php b/src/Symfony/Component/Console/Descriptor/Json/AbstractJsonDescriptor.php index 39603108086a2..b4555d1c18d81 100644 --- a/src/Symfony/Component/Console/Descriptor/Json/AbstractJsonDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Json/AbstractJsonDescriptor.php @@ -36,7 +36,9 @@ public function __construct($encodingOptions = 0) */ public function configure(array $options) { - $this->encodingOptions = $options['json_encoding']; + if (isset($options['json_encoding'])) { + $this->encodingOptions = $options['json_encoding']; + } return $this; } diff --git a/src/Symfony/Component/Console/Descriptor/Json/ApplicationJsonDescriptor.php b/src/Symfony/Component/Console/Descriptor/Json/ApplicationJsonDescriptor.php index 356b4ed71e3d4..acb8bb7707fc4 100644 --- a/src/Symfony/Component/Console/Descriptor/Json/ApplicationJsonDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Json/ApplicationJsonDescriptor.php @@ -39,7 +39,9 @@ public function __construct($namespace = null, $encodingOptions = 0) */ public function configure(array $options) { - $this->namespace = $options['namespace']; + if (isset($options['namespace'])) { + $this->namespace = $options['namespace']; + } return parent::configure($options); } diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/AbstractMarkdownDescriptor.php b/src/Symfony/Component/Console/Descriptor/Markdown/AbstractMarkdownDescriptor.php index 2c00b30067ee4..5f393666d4e94 100644 --- a/src/Symfony/Component/Console/Descriptor/Markdown/AbstractMarkdownDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Markdown/AbstractMarkdownDescriptor.php @@ -36,7 +36,9 @@ public function __construct($maxWidth = 120) */ public function configure(array $options) { - $this->maxWidth = $options['markdown_width']; + if (isset($options['markdown_width'])) { + $this->maxWidth = $options['markdown_width']; + } return $this; } diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/ApplicationMarkdownDescriptor.php b/src/Symfony/Component/Console/Descriptor/Markdown/ApplicationMarkdownDescriptor.php index 64b61a4488459..ae12cdaae85f8 100644 --- a/src/Symfony/Component/Console/Descriptor/Markdown/ApplicationMarkdownDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Markdown/ApplicationMarkdownDescriptor.php @@ -39,7 +39,9 @@ public function __construct($namespace = null, $maxWidth = 120) */ public function configure(array $options) { - $this->namespace = $options['namespace']; + if (isset($options['namespace'])) { + $this->namespace = $options['namespace']; + } return parent::configure($options); } diff --git a/src/Symfony/Component/Console/Descriptor/Xml/AbstractXmlDescriptor.php b/src/Symfony/Component/Console/Descriptor/Xml/AbstractXmlDescriptor.php new file mode 100644 index 0000000000000..051c41be14f51 --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Xml/AbstractXmlDescriptor.php @@ -0,0 +1,64 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Descriptor\Xml; + +use Symfony\Component\Console\Descriptor\DescriptorInterface; + +/** + * @author Jean-François Simon + */ +abstract class AbstractXmlDescriptor implements DescriptorInterface +{ + /** + * {@inheritdoc} + */ + public function configure(array $options) + { + return $this; + } + + /** + * {@inheritdoc} + */ + public function describe($object, $raw = false) + { + $document = new \DOMDocument('1.0', 'UTF-8'); + $document->formatOutput = true; + $this->buildDocument($document, $object); + + return $document->saveXML(); + } + + /** + * Builds DOM document with object. + * + * @param \DOMNode $parent + * @param object $object + */ + abstract public function buildDocument(\DOMNode $parent, $object); + + /** + * {@inheritdoc} + */ + public function getFormat() + { + return 'xml'; + } + + /** + * {@inheritdoc} + */ + public function useFormatting() + { + return false; + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Xml/ApplicationXmlDescriptor.php b/src/Symfony/Component/Console/Descriptor/Xml/ApplicationXmlDescriptor.php new file mode 100644 index 0000000000000..cf1d6efe8cc45 --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Xml/ApplicationXmlDescriptor.php @@ -0,0 +1,91 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Descriptor\Xml; + +use Symfony\Component\Console\Application; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Descriptor\ApplicationDescription; + +/** + * @author Jean-François Simon + */ +class ApplicationXmlDescriptor extends AbstractXmlDescriptor +{ + /** + * @var string|null + */ + private $namespace; + + /** + * @param string|null $namespace + */ + public function __construct($namespace = null) + { + $this->namespace = $namespace; + } + + /** + * {@inheritdoc} + */ + public function configure(array $options) + { + if (isset($options['namespace'])) { + $this->namespace = $options['namespace']; + } + + return parent::configure($options); + } + + /** + * {@inheritdoc} + */ + public function buildDocument(\DOMNode $parent, $object) + { + $dom = $parent instanceof \DOMDocument ? $parent : $parent->ownerDocument; + $dom->appendChild($rootXml = $dom->createElement('symfony')); + $rootXml->appendChild($commandsXML = $dom->createElement('commands')); + + /** @var Application $object */ + $description = new ApplicationDescription($object, $this->namespace); + $descriptor = new CommandXmlDescriptor(); + + if ($this->namespace) { + $commandsXML->setAttribute('namespace', $this->namespace); + } + + foreach ($description->getCommands() as $command) { + $descriptor->buildDocument($commandsXML, $command); + } + + if (!$this->namespace) { + $rootXml->appendChild($namespacesXML = $dom->createElement('namespaces')); + + foreach ($description->getNamespaces() as $namespace) { + $namespacesXML->appendChild($namespaceArrayXML = $dom->createElement('namespace')); + $namespaceArrayXML->setAttribute('id', $namespace['id']); + + foreach ($namespace['commands'] as $name) { + $namespaceArrayXML->appendChild($commandXML = $dom->createElement('command')); + $commandXML->appendChild($dom->createTextNode($name)); + } + } + } + } + + /** + * {@inheritdoc} + */ + public function supports($object) + { + return $object instanceof Application; + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Xml/CommandXmlDescriptor.php b/src/Symfony/Component/Console/Descriptor/Xml/CommandXmlDescriptor.php new file mode 100644 index 0000000000000..21f8b45f966c8 --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Xml/CommandXmlDescriptor.php @@ -0,0 +1,59 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Descriptor\Xml; + +use Symfony\Component\Console\Command\Command; + +/** + * @author Jean-François Simon + */ +class CommandXmlDescriptor extends AbstractXmlDescriptor +{ + /** + * {@inheritdoc} + */ + public function buildDocument(\DOMNode $parent, $object) + { + $dom = $parent instanceof \DOMDocument ? $parent : $parent->ownerDocument; + $parent->appendChild($commandXML = $dom->createElement('command')); + + /** @var Command $object */ + $commandXML->setAttribute('id', $object->getName()); + $commandXML->setAttribute('name', $object->getName()); + + $commandXML->appendChild($usageXML = $dom->createElement('usage')); + $usageXML->appendChild($dom->createTextNode(sprintf($object->getSynopsis(), ''))); + + $commandXML->appendChild($descriptionXML = $dom->createElement('description')); + $descriptionXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $object->getDescription()))); + + $commandXML->appendChild($helpXML = $dom->createElement('help')); + $helpXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $object->getProcessedHelp()))); + + $commandXML->appendChild($aliasesXML = $dom->createElement('aliases')); + foreach ($object->getAliases() as $alias) { + $aliasesXML->appendChild($aliasXML = $dom->createElement('alias')); + $aliasXML->appendChild($dom->createTextNode($alias)); + } + + $descriptor = new InputDefinitionXmlDescriptor(); + $descriptor->buildDocument($commandXML, $object->getDefinition()); + } + + /** + * {@inheritdoc} + */ + public function supports($object) + { + return $object instanceof Command; + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Xml/InputArgumentXmlDescriptor.php b/src/Symfony/Component/Console/Descriptor/Xml/InputArgumentXmlDescriptor.php new file mode 100644 index 0000000000000..b2391e6ff8c9b --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Xml/InputArgumentXmlDescriptor.php @@ -0,0 +1,51 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Descriptor\Xml; + +use Symfony\Component\Console\Input\InputArgument; + +/** + * @author Jean-François Simon + */ +class InputArgumentXmlDescriptor extends AbstractXmlDescriptor +{ + /** + * {@inheritdoc} + */ + public function buildDocument(\DOMNode $parent, $object) + { + $dom = $parent instanceof \DOMDocument ? $parent : $parent->ownerDocument; + + /** @var InputArgument $object */ + $parent->appendChild($objectXML = $dom->createElement('argument')); + $objectXML->setAttribute('name', $object->getName()); + $objectXML->setAttribute('is_required', $object->isRequired() ? 1 : 0); + $objectXML->setAttribute('is_array', $object->isArray() ? 1 : 0); + $objectXML->appendChild($descriptionXML = $dom->createElement('description')); + $descriptionXML->appendChild($dom->createTextNode($object->getDescription())); + + $objectXML->appendChild($defaultsXML = $dom->createElement('defaults')); + $defaults = is_array($object->getDefault()) ? $object->getDefault() : (is_bool($object->getDefault()) ? array(var_export($object->getDefault(), true)) : ($object->getDefault() ? array($object->getDefault()) : array())); + foreach ($defaults as $default) { + $defaultsXML->appendChild($defaultXML = $dom->createElement('default')); + $defaultXML->appendChild($dom->createTextNode($default)); + } + } + + /** + * {@inheritdoc} + */ + public function supports($object) + { + return $object instanceof InputArgument; + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Xml/InputDefinitionXmlDescriptor.php b/src/Symfony/Component/Console/Descriptor/Xml/InputDefinitionXmlDescriptor.php new file mode 100644 index 0000000000000..99865fd114d25 --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Xml/InputDefinitionXmlDescriptor.php @@ -0,0 +1,54 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Descriptor\Xml; + +use Symfony\Component\Console\Input\InputDefinition; + +/** + * @author Jean-François Simon + */ +class InputDefinitionXmlDescriptor extends AbstractXmlDescriptor +{ + /** + * {@inheritdoc} + */ + public function buildDocument(\DOMNode $parent, $object) + { + if ($parent instanceof \DOMDocument) { + $dom = $parent; + $parent->appendChild($parent = $dom->createElement('definition')); + } else { + $dom = $parent->ownerDocument; + } + + $parent->appendChild($argumentsXML = $dom->createElement('arguments')); + $descriptor = new InputArgumentXmlDescriptor(); + /** @var InputDefinition $object */ + foreach ($object->getArguments() as $argument) { + $descriptor->buildDocument($argumentsXML, $argument); + } + + $parent->appendChild($optionsXML = $dom->createElement('options')); + $descriptor = new InputOptionXmlDescriptor(); + foreach ($object->getOptions() as $option) { + $descriptor->buildDocument($optionsXML, $option); + } + } + + /** + * {@inheritdoc} + */ + public function supports($object) + { + return $object instanceof InputDefinition; + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Xml/InputOptionXmlDescriptor.php b/src/Symfony/Component/Console/Descriptor/Xml/InputOptionXmlDescriptor.php new file mode 100644 index 0000000000000..40870b8d41e1b --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Xml/InputOptionXmlDescriptor.php @@ -0,0 +1,58 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Descriptor\Xml; + +use Symfony\Component\Console\Input\InputOption; + +/** + * @author Jean-François Simon + */ +class InputOptionXmlDescriptor extends AbstractXmlDescriptor +{ + /** + * {@inheritdoc} + */ + public function buildDocument(\DOMNode $parent, $object) + { + $dom = $parent instanceof \DOMDocument ? $parent : $parent->ownerDocument; + + /** @var InputOption $object */ + $parent->appendChild($objectXML = $dom->createElement('option')); + $objectXML->setAttribute('name', '--'.$object->getName()); + $objectXML->setAttribute('shortcut', $object->getShortcut() ? '-'.$object->getShortcut() : ''); + $objectXML->setAttribute('accept_value', $object->acceptValue() ? 1 : 0); + $objectXML->setAttribute('is_value_required', $object->isValueRequired() ? 1 : 0); + $objectXML->setAttribute('is_multiple', $object->isArray() ? 1 : 0); + $objectXML->appendChild($descriptionXML = $dom->createElement('description')); + $descriptionXML->appendChild($dom->createTextNode($object->getDescription())); + + if ($object->acceptValue()) { + $defaults = is_array($object->getDefault()) ? $object->getDefault() : (is_bool($object->getDefault()) ? array(var_export($object->getDefault(), true)) : ($object->getDefault() ? array($object->getDefault()) : array())); + + if (!empty($defaults)) { + $objectXML->appendChild($defaultsXML = $dom->createElement('defaults')); + foreach ($defaults as $default) { + $defaultsXML->appendChild($defaultXML = $dom->createElement('default')); + $defaultXML->appendChild($dom->createTextNode($default)); + } + } + } + } + + /** + * {@inheritdoc} + */ + public function supports($object) + { + return $object instanceof InputOption; + } +} diff --git a/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php index 45769a429b9ff..0ca0ace266376 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Console\Tests\Descriptor; +use Symfony\Component\Console\Application; use Symfony\Component\Console\Descriptor\DescriptorInterface; use Symfony\Component\Console\Input\InputArgument; @@ -19,6 +20,10 @@ abstract class AbstractDescriptorTest extends \PHPUnit_Framework_TestCase /** @dataProvider getDescribeTestData */ public function testDescribe(DescriptorInterface $descriptor, $object, $description) { + if ($object instanceof Application) { + $this->ensureStaticCommandHelp($object); + } + $this->assertTrue($descriptor->supports($object)); $this->assertEquals(trim($description), trim($descriptor->describe($object))); } @@ -38,4 +43,16 @@ public function getDescribeTestData() abstract protected function getDescriptor(); abstract protected function getObjects(); + + /** + * Replaces the dynamic placeholders of the command help text with a static version. + * The placeholder %command.full_name% includes the script path that is not predictable + * and can not be tested against. + */ + private function ensureStaticCommandHelp(Application $application) + { + foreach ($application->all() as $command) { + $command->setHelp(str_replace('%command.full_name%', 'app/console %command.name%', $command->getHelp())); + } + } } diff --git a/src/Symfony/Component/Console/Tests/Descriptor/Xml/ApplicationXmlDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/Xml/ApplicationXmlDescriptorTest.php new file mode 100644 index 0000000000000..0fde188177461 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Descriptor/Xml/ApplicationXmlDescriptorTest.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Tests\Descriptor\Json; + +use Symfony\Component\Console\Descriptor\Xml\ApplicationXmlDescriptor; +use Symfony\Component\Console\Tests\Descriptor\AbstractDescriptorTest; +use Symfony\Component\Console\Tests\Descriptor\ObjectsProvider; + +class ApplicationXmlDescriptorTest extends AbstractDescriptorTest +{ + protected function getDescriptor() + { + return new ApplicationXmlDescriptor(); + } + + protected function getObjects() + { + return ObjectsProvider::getApplications(); + } +} diff --git a/src/Symfony/Component/Console/Tests/Descriptor/Xml/CommandXmlDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/Xml/CommandXmlDescriptorTest.php new file mode 100644 index 0000000000000..ca7ac95a74e7b --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Descriptor/Xml/CommandXmlDescriptorTest.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Tests\Descriptor\Json; + +use Symfony\Component\Console\Descriptor\Xml\CommandXmlDescriptor; +use Symfony\Component\Console\Tests\Descriptor\AbstractDescriptorTest; +use Symfony\Component\Console\Tests\Descriptor\ObjectsProvider; + +class CommandXmlDescriptorTest extends AbstractDescriptorTest +{ + protected function getDescriptor() + { + return new CommandXmlDescriptor(); + } + + protected function getObjects() + { + return ObjectsProvider::getCommands(); + } +} diff --git a/src/Symfony/Component/Console/Tests/Descriptor/Xml/InputArgumentXmlDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/Xml/InputArgumentXmlDescriptorTest.php new file mode 100644 index 0000000000000..03cb73c27b44d --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Descriptor/Xml/InputArgumentXmlDescriptorTest.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Tests\Descriptor\Json; + +use Symfony\Component\Console\Descriptor\Xml\InputArgumentXmlDescriptor; +use Symfony\Component\Console\Tests\Descriptor\AbstractDescriptorTest; +use Symfony\Component\Console\Tests\Descriptor\ObjectsProvider; + +class InputArgumentXmlDescriptorTest extends AbstractDescriptorTest +{ + protected function getDescriptor() + { + return new InputArgumentXmlDescriptor(); + } + + protected function getObjects() + { + return ObjectsProvider::getInputArguments(); + } +} diff --git a/src/Symfony/Component/Console/Tests/Descriptor/Xml/InputDefinitionXmlDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/Xml/InputDefinitionXmlDescriptorTest.php new file mode 100644 index 0000000000000..6ca79ef1ea8ac --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Descriptor/Xml/InputDefinitionXmlDescriptorTest.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Tests\Descriptor\Json; + +use Symfony\Component\Console\Descriptor\Xml\InputDefinitionXmlDescriptor; +use Symfony\Component\Console\Tests\Descriptor\AbstractDescriptorTest; +use Symfony\Component\Console\Tests\Descriptor\ObjectsProvider; + +class InputDefinitionXmlDescriptorTest extends AbstractDescriptorTest +{ + protected function getDescriptor() + { + return new InputDefinitionXmlDescriptor(); + } + + protected function getObjects() + { + return ObjectsProvider::getInputDefinitions(); + } +} diff --git a/src/Symfony/Component/Console/Tests/Descriptor/Xml/InputOptionXmlDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/Xml/InputOptionXmlDescriptorTest.php new file mode 100644 index 0000000000000..e2da24f2c74f7 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Descriptor/Xml/InputOptionXmlDescriptorTest.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Tests\Descriptor\Json; + +use Symfony\Component\Console\Descriptor\Xml\InputOptionXmlDescriptor; +use Symfony\Component\Console\Tests\Descriptor\AbstractDescriptorTest; +use Symfony\Component\Console\Tests\Descriptor\ObjectsProvider; + +class InputOptionXmlDescriptorTest extends AbstractDescriptorTest +{ + protected function getDescriptor() + { + return new InputOptionXmlDescriptor(); + } + + protected function getObjects() + { + return ObjectsProvider::getInputOptions(); + } +} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.json b/src/Symfony/Component/Console/Tests/Fixtures/application_1.json index 9f3d2820cd2b4..085989bd58cd0 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_1.json +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.json @@ -1 +1 @@ -{"commands":[{"name":"help","usage":"help [--format[=\"...\"]] [--raw] [command_name]","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php \/usr\/bin\/phpunit help list<\/info>\n\nYou can also output the help as XML by using the --xml<\/comment> option:\n\n php \/usr\/bin\/phpunit help --xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":false,"is_multiple":false,"description":"Output format (json, md)","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false}}}},{"name":"list","usage":"list [--format[=\"...\"]] [--raw] [namespace]","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php \/usr\/bin\/phpunit list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php \/usr\/bin\/phpunit list test<\/info>\n\nYou can also output the information as XML by using the --xml<\/comment> option:\n\n php \/usr\/bin\/phpunit list --xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php \/usr\/bin\/phpunit list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":false,"is_multiple":false,"description":"Output format (json, md)","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false}}}}],"namespaces":[{"id":"_global","commands":["help","list"]}]} +{"commands":[{"name":"help","usage":"help [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the --format<\/comment> option:\n\n php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false}}}},{"name":"list","usage":"list [--format=\"...\"] [--raw] [namespace]","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the --format<\/comment> option:\n\n php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php app\/console list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false}}}}],"namespaces":[{"id":"_global","commands":["help","list"]}]} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.md b/src/Symfony/Component/Console/Tests/Fixtures/application_1.md index bb0ce0371d7d4..19fb2aa422ec0 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_1.md +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.md @@ -8,16 +8,16 @@ help ---- * Description: Displays help for a command -* Usage: `help [--format[="..."]] [--raw] [command_name]` +* Usage: `help [--format="..."] [--raw] [command_name]` * Aliases: The help command displays help for a given command: - php /usr/bin/phpunit help list + php app/console help list -You can also output the help as XML by using the --xml option: +You can also output the help in other formats by using the --format option: - php /usr/bin/phpunit help --xml list + php app/console help --format=xml list To display the list of available commands, please use the list command. @@ -38,9 +38,9 @@ To display the list of available commands, please use the list comm * Name: `--format` * Shortcut: * Accept value: yes -* Is value required: no +* Is value required: yes * Is multiple: no -* Description: Output format (json, md) +* Description: To output help in other formats * Default: `NULL` **raw:** @@ -57,24 +57,24 @@ list ---- * Description: Lists commands -* Usage: `list [--format[="..."]] [--raw] [namespace]` +* Usage: `list [--format="..."] [--raw] [namespace]` * Aliases: The list command lists all commands: - php /usr/bin/phpunit list + php app/console list You can also display the commands for a specific namespace: - php /usr/bin/phpunit list test + php app/console list test -You can also output the information as XML by using the --xml option: +You can also output the information in other formats by using the --format option: - php /usr/bin/phpunit list --xml + php app/console list --format=xml It's also possible to get raw list of commands (useful for embedding command runner): - php /usr/bin/phpunit list --raw + php app/console list --raw ### Arguments: @@ -93,9 +93,9 @@ It's also possible to get raw list of commands (useful for embedding command run * Name: `--format` * Shortcut: * Accept value: yes -* Is value required: no +* Is value required: yes * Is multiple: no -* Description: Output format (json, md) +* Description: To output help in other formats * Default: `NULL` **raw:** diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml b/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml new file mode 100644 index 0000000000000..38ea50b126d80 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml @@ -0,0 +1,75 @@ + + + + + help [--format="..."] [--raw] [command_name] + Displays help for a command + The <info>help</info> command displays help for a given command: + + <info>php app/console help list</info> + + You can also output the help in other formats by using the <comment>--format</comment> option: + + <info>php app/console help --format=xml list</info> + + To display the list of available commands, please use the <info>list</info> command. + + + + The command name + + help + + + + + + + + + + list [--format="..."] [--raw] [namespace] + Lists commands + The <info>list</info> command lists all commands: + + <info>php app/console list</info> + + You can also display the commands for a specific namespace: + + <info>php app/console list test</info> + + You can also output the information in other formats by using the <comment>--format</comment> option: + + <info>php app/console list --format=xml</info> + + It's also possible to get raw list of commands (useful for embedding command runner): + + <info>php app/console list --raw</info> + + + + The namespace name + + + + + + + + + + + + help + list + + + diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml~ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml~ new file mode 100644 index 0000000000000..2fe106c4c23a4 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml~ @@ -0,0 +1,75 @@ + + + + + help [--format="..."] [--raw] [command_name] + Displays help for a command + The <info>help</info> command displays help for a given command: + + <info>php app/console help list</info> + + You can also output the help as XML by using the <comment>--format</comment> option: + + <info>php app/console help --format=xml list</info> + + To display the list of available commands, please use the <info>list</info> command. + + + + The command name + + help + + + + + + + + + + list [--format="..."] [--raw] [namespace] + Lists commands + The <info>list</info> command lists all commands: + + <info>php app/console list</info> + + You can also display the commands for a specific namespace: + + <info>php app/console list test</info> + + You can also output the information as XML by using the <comment>--format</comment> option: + + <info>php app/console list --format=xml</info> + + It's also possible to get raw list of commands (useful for embedding command runner): + + <info>php app/console list --raw</info> + + + + The namespace name + + + + + + + + + + + + help + list + + + diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.json b/src/Symfony/Component/Console/Tests/Fixtures/application_2.json index 5871aef56d84a..f7a1386f021b7 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_2.json +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.json @@ -1 +1 @@ -{"commands":[{"name":"help","usage":"help [--format[=\"...\"]] [--raw] [command_name]","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php \/usr\/bin\/phpunit help list<\/info>\n\nYou can also output the help as XML by using the --xml<\/comment> option:\n\n php \/usr\/bin\/phpunit help --xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":false,"is_multiple":false,"description":"Output format (json, md)","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false}}}},{"name":"list","usage":"list [--format[=\"...\"]] [--raw] [namespace]","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php \/usr\/bin\/phpunit list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php \/usr\/bin\/phpunit list test<\/info>\n\nYou can also output the information as XML by using the --xml<\/comment> option:\n\n php \/usr\/bin\/phpunit list --xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php \/usr\/bin\/phpunit list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":false,"is_multiple":false,"description":"Output format (json, md)","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false}}}},{"name":"descriptor:command1","usage":"descriptor:command1","description":"command 1 description","help":"command 1 help","aliases":["alias1","alias2"],"definition":{"arguments":[],"options":[]}},{"name":"descriptor:command2","usage":"descriptor:command2 [-o|--option_name] argument_name","description":"command 2 description","help":"command 2 help","aliases":[],"definition":{"arguments":{"argument_name":{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null}},"options":{"option_name":{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false}}}}],"namespaces":[{"id":"_global","commands":["alias1","alias2","help","list"]},{"id":"descriptor","commands":["descriptor:command1","descriptor:command2"]}]} +{"commands":[{"name":"help","usage":"help [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the --format<\/comment> option:\n\n php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false}}}},{"name":"list","usage":"list [--format=\"...\"] [--raw] [namespace]","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the --format<\/comment> option:\n\n php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php app\/console list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false}}}},{"name":"descriptor:command1","usage":"descriptor:command1","description":"command 1 description","help":"command 1 help","aliases":["alias1","alias2"],"definition":{"arguments":[],"options":[]}},{"name":"descriptor:command2","usage":"descriptor:command2 [-o|--option_name] argument_name","description":"command 2 description","help":"command 2 help","aliases":[],"definition":{"arguments":{"argument_name":{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null}},"options":{"option_name":{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false}}}}],"namespaces":[{"id":"_global","commands":["alias1","alias2","help","list"]},{"id":"descriptor","commands":["descriptor:command1","descriptor:command2"]}]} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.md b/src/Symfony/Component/Console/Tests/Fixtures/application_2.md index d06a11c842979..cd21bdd1aa7f7 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_2.md +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.md @@ -15,16 +15,16 @@ help ---- * Description: Displays help for a command -* Usage: `help [--format[="..."]] [--raw] [command_name]` +* Usage: `help [--format="..."] [--raw] [command_name]` * Aliases: The help command displays help for a given command: - php /usr/bin/phpunit help list + php app/console help list -You can also output the help as XML by using the --xml option: +You can also output the help in other formats by using the --format option: - php /usr/bin/phpunit help --xml list + php app/console help --format=xml list To display the list of available commands, please use the list command. @@ -45,9 +45,9 @@ To display the list of available commands, please use the list comm * Name: `--format` * Shortcut: * Accept value: yes -* Is value required: no +* Is value required: yes * Is multiple: no -* Description: Output format (json, md) +* Description: To output help in other formats * Default: `NULL` **raw:** @@ -64,24 +64,24 @@ list ---- * Description: Lists commands -* Usage: `list [--format[="..."]] [--raw] [namespace]` +* Usage: `list [--format="..."] [--raw] [namespace]` * Aliases: The list command lists all commands: - php /usr/bin/phpunit list + php app/console list You can also display the commands for a specific namespace: - php /usr/bin/phpunit list test + php app/console list test -You can also output the information as XML by using the --xml option: +You can also output the information in other formats by using the --format option: - php /usr/bin/phpunit list --xml + php app/console list --format=xml It's also possible to get raw list of commands (useful for embedding command runner): - php /usr/bin/phpunit list --raw + php app/console list --raw ### Arguments: @@ -100,9 +100,9 @@ It's also possible to get raw list of commands (useful for embedding command run * Name: `--format` * Shortcut: * Accept value: yes -* Is value required: no +* Is value required: yes * Is multiple: no -* Description: Output format (json, md) +* Description: To output help in other formats * Default: `NULL` **raw:** diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.xml b/src/Symfony/Component/Console/Tests/Fixtures/application_2.xml new file mode 100644 index 0000000000000..2fda065c6fc83 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.xml @@ -0,0 +1,109 @@ + + + + + help [--format="..."] [--raw] [command_name] + Displays help for a command + The <info>help</info> command displays help for a given command: + + <info>php app/console help list</info> + + You can also output the help in other formats by using the <comment>--format</comment> option: + + <info>php app/console help --format=xml list</info> + + To display the list of available commands, please use the <info>list</info> command. + + + + The command name + + help + + + + + + + + + + list [--format="..."] [--raw] [namespace] + Lists commands + The <info>list</info> command lists all commands: + + <info>php app/console list</info> + + You can also display the commands for a specific namespace: + + <info>php app/console list test</info> + + You can also output the information in other formats by using the <comment>--format</comment> option: + + <info>php app/console list --format=xml</info> + + It's also possible to get raw list of commands (useful for embedding command runner): + + <info>php app/console list --raw</info> + + + + The namespace name + + + + + + + + + + descriptor:command1 + command 1 description + command 1 help + + alias1 + alias2 + + + + + + descriptor:command2 [-o|--option_name] argument_name + command 2 description + command 2 help + + + + + + + + + + + + + + + alias1 + alias2 + help + list + + + descriptor:command1 + descriptor:command2 + + + diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.xml~ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.xml~ new file mode 100644 index 0000000000000..7c792c3ec136c --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.xml~ @@ -0,0 +1,109 @@ + + + + + help [--format="..."] [--raw] [command_name] + Displays help for a command + The <info>help</info> command displays help for a given command: + + <info>php app/console help list</info> + + You can also output the help in other formats by using the <comment>--format</comment> option: + + <info>php app/console help --format=xml list</info> + + To display the list of available commands, please use the <info>list</info> command. + + + + The command name + + help + + + + + + + + + + list [--format="..."] [--raw] [namespace] + Lists commands + The <info>list</info> command lists all commands: + + <info>php app/console list</info> + + You can also display the commands for a specific namespace: + + <info>php app/console list test</info> + + You can also output the information in other formats by using the <comment>--format</comment> option: + + <info>php app/console list --format=xml</info> + + It's also possible to get raw list of commands (useful for embedding command runner): + + <info>php app/console list --raw</info> + + + + The namespace name + + + + + + + + + + descriptor:command1 + command 1 description + command 1 help + + alias1 + alias2 + + + + + + descriptor:command2 [-o|--option_name] argument_name + command 2 description + command 2 help + + + + + + + + + + + + + + + alias1 + alias2 + help + list + + + descriptor:command1 + descriptor:command2 + + + diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt index 068306a24fd3c..fc8a946e08ac2 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt @@ -6,6 +6,6 @@ -list [--format[="..."]] [--raw] [namespace] +list [--format="..."] [--raw] [namespace] diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt~ b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt~ new file mode 100644 index 0000000000000..152eadf99377e --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt~ @@ -0,0 +1,11 @@ + + + + [InvalidArgumentException] + The "--foo" option does not exist. + + + +list [--format="..."] [--raw] [namespace] + + diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_run2.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_run2.txt index 6831afdd128c1..8b17c7f6bb0f7 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_run2.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_run2.txt @@ -6,7 +6,7 @@ Arguments: command_name The command name (default: "help") Options: - --xml To output help as XML + --format To output help in other formats. --help (-h) Display this help message. --quiet (-q) Do not output any message. --verbose (-v) Increase verbosity of messages. @@ -17,12 +17,12 @@ Options: Help: The help command displays help for a given command: - + php app/console help list - - You can also output the help as XML by using the --xml option: - - php app/console help --xml list - + + You can also output the help in other formats by using the --format option: + + php app/console help --format=xml list + To display the list of available commands, please use the list command. diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_run3.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_run3.txt index 441db5485752c..a203c737e4147 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_run3.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_run3.txt @@ -5,23 +5,23 @@ Arguments: namespace The namespace name Options: - --xml To output help as XML + --format To output help in other formats --raw To output raw command list Help: The list command lists all commands: - + php app/console list - + You can also display the commands for a specific namespace: - + php app/console list test - - You can also output the information as XML by using the --xml option: - - php app/console list --xml - + + You can also output the information in other formats by using the --format option: + + php app/console list --format=xml + It's also possible to get raw list of commands (useful for embedding command runner): - + php app/console list --raw diff --git a/src/Symfony/Component/Console/Tests/Fixtures/command_1.xml b/src/Symfony/Component/Console/Tests/Fixtures/command_1.xml new file mode 100644 index 0000000000000..dcfa6fa5044e7 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/command_1.xml @@ -0,0 +1,12 @@ + + + descriptor:command1 + command 1 description + command 1 help + + alias1 + alias2 + + + + diff --git a/src/Symfony/Component/Console/Tests/Fixtures/command_2.xml b/src/Symfony/Component/Console/Tests/Fixtures/command_2.xml new file mode 100644 index 0000000000000..c411c36c3d285 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/command_2.xml @@ -0,0 +1,18 @@ + + + descriptor:command2 [-o|--option_name] argument_name + command 2 description + command 2 help + + + + + + + + + + + diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_argument_1.xml b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_1.xml new file mode 100644 index 0000000000000..cb37f812c5ec4 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_1.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_argument_2.xml b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_2.xml new file mode 100644 index 0000000000000..629da5a98a3b5 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_2.xml @@ -0,0 +1,5 @@ + + + argument description + + diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_argument_3.xml b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_3.xml new file mode 100644 index 0000000000000..399a5c864d5dd --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_3.xml @@ -0,0 +1,7 @@ + + + argument description + + default_value + + diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_definition_1.xml b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_1.xml new file mode 100644 index 0000000000000..b5481ce1276a2 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_1.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_definition_2.xml b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_2.xml new file mode 100644 index 0000000000000..102efc1486381 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_2.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_definition_3.xml b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_3.xml new file mode 100644 index 0000000000000..bc95151548ada --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_3.xml @@ -0,0 +1,9 @@ + + + + + + + diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_definition_4.xml b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_4.xml new file mode 100644 index 0000000000000..cffceecef14c7 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_4.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_1.xml b/src/Symfony/Component/Console/Tests/Fixtures/input_option_1.xml new file mode 100644 index 0000000000000..8a64ea65296e6 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_1.xml @@ -0,0 +1,4 @@ + + diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_2.xml b/src/Symfony/Component/Console/Tests/Fixtures/input_option_2.xml new file mode 100644 index 0000000000000..4afac5b04e10d --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_2.xml @@ -0,0 +1,7 @@ + + diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_3.xml b/src/Symfony/Component/Console/Tests/Fixtures/input_option_3.xml new file mode 100644 index 0000000000000..52f87dfa92e9c --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_3.xml @@ -0,0 +1,4 @@ + + diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_4.xml b/src/Symfony/Component/Console/Tests/Fixtures/input_option_4.xml new file mode 100644 index 0000000000000..6eecd07ea879e --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_4.xml @@ -0,0 +1,4 @@ + + From 47fa194a7c927023ee0317c6c9583cbf1ddb21a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Sat, 6 Apr 2013 15:47:21 +0200 Subject: [PATCH 08/24] [Console] started text derciptors --- .../Descriptor/ApplicationDescription.php | 52 +++++++- .../Descriptor/DescriptorInterface.php | 3 +- .../Console/Descriptor/DescriptorProvider.php | 6 + .../Json/AbstractJsonDescriptor.php | 16 +-- .../Json/ApplicationJsonDescriptor.php | 2 +- .../Descriptor/Json/CommandJsonDescriptor.php | 2 +- .../Json/InputDefinitionJsonDescriptor.php | 4 +- .../Markdown/AbstractMarkdownDescriptor.php | 2 +- .../Text/AbstractTextDescriptor.php | 87 +++++++++++++ .../Text/ApplicationTextDescriptor.php | 117 ++++++++++++++++++ .../Descriptor/Xml/AbstractXmlDescriptor.php | 2 +- .../Console/Helper/DescriptorHelper.php | 4 +- 12 files changed, 270 insertions(+), 27 deletions(-) create mode 100644 src/Symfony/Component/Console/Descriptor/Text/AbstractTextDescriptor.php create mode 100644 src/Symfony/Component/Console/Descriptor/Text/ApplicationTextDescriptor.php diff --git a/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php b/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php index 775be0fbbc9bc..90e27dad696e1 100644 --- a/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php +++ b/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php @@ -21,17 +21,41 @@ class ApplicationDescription { const GLOBAL_NAMESPACE = '_global'; + /** + * @var Application + */ private $application; + + /** + * @var null|string + */ private $namespace; + + /** + * @var array + */ private $namespaces; + + /** + * @var Command[] + */ private $commands; + /** + * Constructor. + * + * @param Application $application + * @param string|null $namespace + */ public function __construct(Application $application, $namespace = null) { $this->application = $application; $this->namespace = $namespace; } + /** + * @return array + */ public function getNamespaces() { if (null === $this->namespaces) { @@ -41,6 +65,9 @@ public function getNamespaces() return $this->namespaces; } + /** + * @return Command[] + */ public function getCommands() { if (null === $this->commands) { @@ -50,6 +77,22 @@ public function getCommands() return $this->commands; } + /** + * @param string $name + * + * @return Command + * + * @throws \InvalidArgumentException + */ + public function getCommand($name) + { + if (!isset($this->commands[$name])) { + throw new \InvalidArgumentException('Command "'.$name.'" does not exist.'); + } + + return $this->commands[$name]; + } + private function inspectApplication() { $this->commands = array(); @@ -67,16 +110,21 @@ private function inspectApplication() // aliases must be skipped in commands list if ($name === $command->getName()) { - $this->commands[] = $command; + $this->commands[$name] = $command; } $names[] = $name; } - $this->namespaces[] = array('id' => $namespace, 'commands' => $names); + $this->namespaces[$namespace] = array('id' => $namespace, 'commands' => $names); } } + /** + * @param array $commands + * + * @return array + */ private function sortCommands(array $commands) { $method = new \ReflectionMethod($this->application, 'sortCommands'); diff --git a/src/Symfony/Component/Console/Descriptor/DescriptorInterface.php b/src/Symfony/Component/Console/Descriptor/DescriptorInterface.php index fe9124f9243f5..efc12cc01a93c 100644 --- a/src/Symfony/Component/Console/Descriptor/DescriptorInterface.php +++ b/src/Symfony/Component/Console/Descriptor/DescriptorInterface.php @@ -29,11 +29,10 @@ public function configure(array $options); * Returns given object's representation. * * @param object $object The object to describe - * @param boolean $raw No additional markers if true * * @return string The object formatted description */ - public function describe($object, $raw = false); + public function describe($object); /** * Tests if this descriptor supports given object. diff --git a/src/Symfony/Component/Console/Descriptor/DescriptorProvider.php b/src/Symfony/Component/Console/Descriptor/DescriptorProvider.php index 73d2228ea1ed9..16ee053913514 100644 --- a/src/Symfony/Component/Console/Descriptor/DescriptorProvider.php +++ b/src/Symfony/Component/Console/Descriptor/DescriptorProvider.php @@ -29,6 +29,7 @@ class DescriptorProvider private $options = array( 'default_format' => 'txt', 'namespace' => null, + 'raw_text' => false, 'json_encoding' => 0, 'markdown_width' => 120, ); @@ -42,6 +43,11 @@ public function __construct(array $options = array()) { $this ->configure($options) + ->add(new Xml\ApplicationXmlDescriptor()) + ->add(new Xml\CommandXmlDescriptor()) + ->add(new Xml\InputDefinitionXmlDescriptor()) + ->add(new Xml\InputArgumentXmlDescriptor()) + ->add(new Xml\InputOptionXmlDescriptor()) ->add(new Json\ApplicationJsonDescriptor()) ->add(new Json\CommandJsonDescriptor()) ->add(new Json\InputDefinitionJsonDescriptor()) diff --git a/src/Symfony/Component/Console/Descriptor/Json/AbstractJsonDescriptor.php b/src/Symfony/Component/Console/Descriptor/Json/AbstractJsonDescriptor.php index b4555d1c18d81..6effd8be75b89 100644 --- a/src/Symfony/Component/Console/Descriptor/Json/AbstractJsonDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Json/AbstractJsonDescriptor.php @@ -46,7 +46,7 @@ public function configure(array $options) /** * {@inheritdoc} */ - public function describe($object, $raw = false) + public function describe($object) { return json_encode($this->getData($object), $this->encodingOptions); } @@ -75,18 +75,4 @@ public function useFormatting() { return false; } - - /** - * Builds a JSON descriptor. - * - * @param AbstractJsonDescriptor $descriptor - * - * @return AbstractJsonDescriptor - */ - protected function build(AbstractJsonDescriptor $descriptor) - { - $descriptor->configure(array('json_encoding' => $this->encodingOptions)); - - return $descriptor; - } } diff --git a/src/Symfony/Component/Console/Descriptor/Json/ApplicationJsonDescriptor.php b/src/Symfony/Component/Console/Descriptor/Json/ApplicationJsonDescriptor.php index acb8bb7707fc4..71b00aae4b977 100644 --- a/src/Symfony/Component/Console/Descriptor/Json/ApplicationJsonDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Json/ApplicationJsonDescriptor.php @@ -53,7 +53,7 @@ public function getData($object) { /** @var Application $object */ $description = new ApplicationDescription($object, $this->namespace); - $descriptor = $this->build(new CommandJsonDescriptor()); + $descriptor = new CommandJsonDescriptor(); $commands = array_map(array($descriptor, 'getData'), $description->getCommands()); return null === $this->namespace diff --git a/src/Symfony/Component/Console/Descriptor/Json/CommandJsonDescriptor.php b/src/Symfony/Component/Console/Descriptor/Json/CommandJsonDescriptor.php index d4bd698180a3b..85d35aa6cf21f 100644 --- a/src/Symfony/Component/Console/Descriptor/Json/CommandJsonDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Json/CommandJsonDescriptor.php @@ -23,7 +23,7 @@ class CommandJsonDescriptor extends AbstractJsonDescriptor */ public function getData($object) { - $definitionDescriptor = $this->build(new InputDefinitionJsonDescriptor()); + $definitionDescriptor = new InputDefinitionJsonDescriptor(); /** @var Command $object */ return array( diff --git a/src/Symfony/Component/Console/Descriptor/Json/InputDefinitionJsonDescriptor.php b/src/Symfony/Component/Console/Descriptor/Json/InputDefinitionJsonDescriptor.php index 4755b0980bc53..9ad445a7b1bc1 100644 --- a/src/Symfony/Component/Console/Descriptor/Json/InputDefinitionJsonDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Json/InputDefinitionJsonDescriptor.php @@ -25,8 +25,8 @@ class InputDefinitionJsonDescriptor extends AbstractJsonDescriptor */ public function getData($object) { - $argumentDescriptor = $this->build(new InputArgumentJsonDescriptor()); - $optionDescriptor = $this->build(new InputOptionJsonDescriptor()); + $argumentDescriptor = new InputArgumentJsonDescriptor(); + $optionDescriptor = new InputOptionJsonDescriptor(); /** @var InputDefinition $object */ return array( diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/AbstractMarkdownDescriptor.php b/src/Symfony/Component/Console/Descriptor/Markdown/AbstractMarkdownDescriptor.php index 5f393666d4e94..3e8366cf4c667 100644 --- a/src/Symfony/Component/Console/Descriptor/Markdown/AbstractMarkdownDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Markdown/AbstractMarkdownDescriptor.php @@ -46,7 +46,7 @@ public function configure(array $options) /** * {@inheritdoc} */ - public function describe($object, $raw = false) + public function describe($object) { return $this->getDocument($object)->format(new Document\Formatter($this->maxWidth)); } diff --git a/src/Symfony/Component/Console/Descriptor/Text/AbstractTextDescriptor.php b/src/Symfony/Component/Console/Descriptor/Text/AbstractTextDescriptor.php new file mode 100644 index 0000000000000..4a6771ab6c99b --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Text/AbstractTextDescriptor.php @@ -0,0 +1,87 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Descriptor\Text; + +use Symfony\Component\Console\Descriptor\DescriptorInterface; + +/** + * @author Jean-François Simon + */ +abstract class AbstractTextDescriptor implements DescriptorInterface +{ + /** + * @var boolean + */ + private $raw; + + /** + * @param boolean $raw + */ + public function __construct($raw = false) + { + $this->raw = $raw; + } + + /** + * {@inheritdoc} + */ + public function configure(array $options) + { + if (isset($options['raw_text'])) { + $this->raw = $options['raw_text']; + } + + return $this; + } + + /** + * {@inheritdoc} + */ + public function describe($object) + { + return $this->raw ? $this->getRawText($object) : $this->getFormattedText($object); + } + + /** + * Returns object's raw text description. + * + * @param object $object + * + * @return string + */ + abstract public function getRawText($object); + + /** + * Returns object's formatted text description. + * + * @param object $object + * + * @return string + */ + abstract public function getFormattedText($object); + + /** + * {@inheritdoc} + */ + public function getFormat() + { + return 'txt'; + } + + /** + * {@inheritdoc} + */ + public function useFormatting() + { + return false; + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Text/ApplicationTextDescriptor.php b/src/Symfony/Component/Console/Descriptor/Text/ApplicationTextDescriptor.php new file mode 100644 index 0000000000000..bfdf6cfbb5083 --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Text/ApplicationTextDescriptor.php @@ -0,0 +1,117 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Descriptor\Text; + +use Symfony\Component\Console\Application; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Descriptor\ApplicationDescription; + +/** + * @author Jean-François Simon + */ +class ApplicationTextDescriptor extends AbstractTextDescriptor +{ + /** + * @var string|null + */ + private $namespace; + + /** + * @param string|null $namespace + */ + public function __construct($namespace = null) + { + $this->namespace = $namespace; + } + + /** + * {@inheritdoc} + */ + public function configure(array $options) + { + if (isset($options['namespace'])) { + $this->namespace = $options['namespace']; + } + + return parent::configure($options); + } + + /** + * {@inheritdoc} + */ + public function getRawText($object) + { + /** @var Application $object */ + $description = new ApplicationDescription($object, $this->namespace); + $width = $this->getColumnWidth($description->getCommands()); + $messages = array(); + + foreach ($description->getCommands() as $command) { + $messages[] = sprintf("%-${width}s %s", $command->getName(), $command->getDescription()); + } + + return implode(PHP_EOL, $messages); + } + + /** + * {@inheritdoc} + */ + public function getFormattedText($object) + { + /** @var Application $object */ + $description = new ApplicationDescription($object, $this->namespace); + $width = $this->getColumnWidth($description->getCommands()); + $messages = array($object->getHelp(), ''); + + if ($this->namespace) { + $messages[] = sprintf("Available commands for the \"%s\" namespace:", $this->namespace); + } else { + $messages[] = 'Available commands:'; + } + + // add commands by namespace + foreach ($description->getNamespaces() as $namespace) { + if (!$this->namespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) { + $messages[] = ''.$namespace['id'].''; + } + + foreach ($namespace['commands'] as $name) { + $messages[] = sprintf(" %-${width}s %s", $name, $description->getCommand($name)->getDescription()); + } + } + + return implode(PHP_EOL, $messages); + } + + /** + * {@inheritdoc} + */ + public function supports($object) + { + return $object instanceof Application; + } + + /** + * @param Command[] $commands + * + * @return int + */ + private function getColumnWidth(array $commands) + { + $width = 0; + foreach ($commands as $command) { + $width = strlen($command->getName()) > $width ? strlen($command->getName()) : $width; + } + + return $width + 2; + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Xml/AbstractXmlDescriptor.php b/src/Symfony/Component/Console/Descriptor/Xml/AbstractXmlDescriptor.php index 051c41be14f51..7a59e6e960e91 100644 --- a/src/Symfony/Component/Console/Descriptor/Xml/AbstractXmlDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Xml/AbstractXmlDescriptor.php @@ -29,7 +29,7 @@ public function configure(array $options) /** * {@inheritdoc} */ - public function describe($object, $raw = false) + public function describe($object) { $document = new \DOMDocument('1.0', 'UTF-8'); $document->formatOutput = true; diff --git a/src/Symfony/Component/Console/Helper/DescriptorHelper.php b/src/Symfony/Component/Console/Helper/DescriptorHelper.php index e8fc7926fdee5..c947f991a22cf 100644 --- a/src/Symfony/Component/Console/Helper/DescriptorHelper.php +++ b/src/Symfony/Component/Console/Helper/DescriptorHelper.php @@ -47,10 +47,10 @@ public function __construct(DescriptorProvider $provider) public function describe(OutputInterface $output, $object, $format = null, $raw = false) { $format = $format ?: $this->provider->getDefaultFormat(); - $descriptor = $this->provider->get($object, $format); + $descriptor = $this->provider->configure(array('raw_text' => $raw))->get($object, $format); $type = $raw && $descriptor->useFormatting() ? OutputInterface::OUTPUT_NORMAL : OutputInterface::OUTPUT_RAW; - $output->writeln($descriptor->describe($object, $format, $raw), $type); + $output->writeln($descriptor->describe($object), $type); } /** From 8b56eb19ced08cd61e282377f3991478b75a5ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Mon, 8 Apr 2013 08:52:47 +0200 Subject: [PATCH 09/24] [Console] finished text descriptors --- .../Command/AbstractDescriptionCommand.php | 5 ++ .../Descriptor/ApplicationDescription.php | 14 ++- .../Console/Descriptor/DescriptorProvider.php | 5 ++ .../Json/ApplicationJsonDescriptor.php | 4 +- .../Text/AbstractTextDescriptor.php | 9 ++ .../Text/ApplicationTextDescriptor.php | 4 +- .../Descriptor/Text/CommandTextDescriptor.php | 60 +++++++++++++ .../Text/InputArgumentTextDescriptor.php | 81 +++++++++++++++++ .../Text/InputDefinitionTextDescriptor.php | 83 ++++++++++++++++++ .../Text/InputOptionTextDescriptor.php | 87 +++++++++++++++++++ .../Console/Tests/Command/HelpCommandTest.php | 5 +- .../Text/ApplicationTextDescriptorTest.php | 29 +++++++ .../Text/CommandTextDescriptorTest.php | 29 +++++++ .../Text/InputArgumentTextDescriptorTest.php | 29 +++++++ .../InputDefinitionTextDescriptorTest.php | 29 +++++++ .../Text/InputOptionTextDescriptorTest.php | 29 +++++++ .../Console/Tests/Fixtures/application_1.txt | 17 ++++ .../Console/Tests/Fixtures/application_2.txt | 22 +++++ .../Console/Tests/Fixtures/command_1.txt | 7 ++ .../Console/Tests/Fixtures/command_2.txt | 11 +++ .../Console/Tests/Fixtures/command_2.txt~ | 12 +++ .../Tests/Fixtures/input_argument_1.txt | 1 + .../Tests/Fixtures/input_argument_2.txt | 1 + .../Tests/Fixtures/input_argument_3.txt | 1 + .../Tests/Fixtures/input_definition_1.txt | 0 .../Tests/Fixtures/input_definition_2.txt | 2 + .../Tests/Fixtures/input_definition_3.txt | 2 + .../Tests/Fixtures/input_definition_4.txt | 5 ++ .../Tests/Fixtures/input_definition_4.txt~ | 5 ++ .../Console/Tests/Fixtures/input_option_1.txt | 1 + .../Console/Tests/Fixtures/input_option_2.txt | 1 + .../Console/Tests/Fixtures/input_option_3.txt | 1 + .../Console/Tests/Fixtures/input_option_4.txt | 1 + 33 files changed, 583 insertions(+), 9 deletions(-) create mode 100644 src/Symfony/Component/Console/Descriptor/Text/CommandTextDescriptor.php create mode 100644 src/Symfony/Component/Console/Descriptor/Text/InputArgumentTextDescriptor.php create mode 100644 src/Symfony/Component/Console/Descriptor/Text/InputDefinitionTextDescriptor.php create mode 100644 src/Symfony/Component/Console/Descriptor/Text/InputOptionTextDescriptor.php create mode 100644 src/Symfony/Component/Console/Tests/Descriptor/Text/ApplicationTextDescriptorTest.php create mode 100644 src/Symfony/Component/Console/Tests/Descriptor/Text/CommandTextDescriptorTest.php create mode 100644 src/Symfony/Component/Console/Tests/Descriptor/Text/InputArgumentTextDescriptorTest.php create mode 100644 src/Symfony/Component/Console/Tests/Descriptor/Text/InputDefinitionTextDescriptorTest.php create mode 100644 src/Symfony/Component/Console/Tests/Descriptor/Text/InputOptionTextDescriptorTest.php create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_1.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_2.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/command_1.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/command_2.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/command_2.txt~ create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_argument_1.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_argument_2.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_argument_3.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_definition_1.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_definition_2.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_definition_3.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_definition_4.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_definition_4.txt~ create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_1.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_2.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_3.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_4.txt diff --git a/src/Symfony/Component/Console/Command/AbstractDescriptionCommand.php b/src/Symfony/Component/Console/Command/AbstractDescriptionCommand.php index 52d716da5af90..ad0d75b46bd96 100644 --- a/src/Symfony/Component/Console/Command/AbstractDescriptionCommand.php +++ b/src/Symfony/Component/Console/Command/AbstractDescriptionCommand.php @@ -4,6 +4,7 @@ use Symfony\Component\Console\Descriptor\DescriptorProvider; use Symfony\Component\Console\Helper\DescriptorHelper; +use Symfony\Component\Console\Helper\HelperSet; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -48,6 +49,10 @@ protected function createDefinition() */ protected function execute(InputInterface $input, OutputInterface $output) { + if (null === $this->getHelperSet()) { + $this->setHelperSet(new HelperSet()); + } + $this->getHelperSet()->set(new DescriptorHelper($this->provider)); } } diff --git a/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php b/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php index 90e27dad696e1..95c124bf15a0a 100644 --- a/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php +++ b/src/Symfony/Component/Console/Descriptor/ApplicationDescription.php @@ -41,6 +41,11 @@ class ApplicationDescription */ private $commands; + /** + * @var Command[] + */ + private $aliases; + /** * Constructor. * @@ -86,11 +91,11 @@ public function getCommands() */ public function getCommand($name) { - if (!isset($this->commands[$name])) { + if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) { throw new \InvalidArgumentException('Command "'.$name.'" does not exist.'); } - return $this->commands[$name]; + return isset($this->commands[$name]) ? $this->commands[$name] : $this->aliases[$name]; } private function inspectApplication() @@ -108,9 +113,10 @@ private function inspectApplication() continue; } - // aliases must be skipped in commands list - if ($name === $command->getName()) { + if ($command->getName() === $name) { $this->commands[$name] = $command; + } else { + $this->aliases[$name] = $command; } $names[] = $name; diff --git a/src/Symfony/Component/Console/Descriptor/DescriptorProvider.php b/src/Symfony/Component/Console/Descriptor/DescriptorProvider.php index 16ee053913514..426275e24fb54 100644 --- a/src/Symfony/Component/Console/Descriptor/DescriptorProvider.php +++ b/src/Symfony/Component/Console/Descriptor/DescriptorProvider.php @@ -43,6 +43,11 @@ public function __construct(array $options = array()) { $this ->configure($options) + ->add(new Text\ApplicationTextDescriptor()) + ->add(new Text\CommandTextDescriptor()) + ->add(new Text\InputDefinitionTextDescriptor()) + ->add(new Text\InputArgumentTextDescriptor()) + ->add(new Text\InputOptionTextDescriptor()) ->add(new Xml\ApplicationXmlDescriptor()) ->add(new Xml\CommandXmlDescriptor()) ->add(new Xml\InputDefinitionXmlDescriptor()) diff --git a/src/Symfony/Component/Console/Descriptor/Json/ApplicationJsonDescriptor.php b/src/Symfony/Component/Console/Descriptor/Json/ApplicationJsonDescriptor.php index 71b00aae4b977..730e3b573c38c 100644 --- a/src/Symfony/Component/Console/Descriptor/Json/ApplicationJsonDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Json/ApplicationJsonDescriptor.php @@ -54,10 +54,10 @@ public function getData($object) /** @var Application $object */ $description = new ApplicationDescription($object, $this->namespace); $descriptor = new CommandJsonDescriptor(); - $commands = array_map(array($descriptor, 'getData'), $description->getCommands()); + $commands = array_values(array_map(array($descriptor, 'getData'), $description->getCommands())); return null === $this->namespace - ? array('commands' => $commands, 'namespaces' => $description->getNamespaces()) + ? array('commands' => $commands, 'namespaces' => array_values($description->getNamespaces())) : array('commands' => $commands, 'namespace' => $this->namespace); } diff --git a/src/Symfony/Component/Console/Descriptor/Text/AbstractTextDescriptor.php b/src/Symfony/Component/Console/Descriptor/Text/AbstractTextDescriptor.php index 4a6771ab6c99b..57e7df01a4d7f 100644 --- a/src/Symfony/Component/Console/Descriptor/Text/AbstractTextDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Text/AbstractTextDescriptor.php @@ -84,4 +84,13 @@ public function useFormatting() { return false; } + + protected function formatDefaultValue($default) + { + if (version_compare(PHP_VERSION, '5.4', '<')) { + return str_replace('\/', '/', json_encode($default)); + } + + return json_encode($default, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + } } diff --git a/src/Symfony/Component/Console/Descriptor/Text/ApplicationTextDescriptor.php b/src/Symfony/Component/Console/Descriptor/Text/ApplicationTextDescriptor.php index bfdf6cfbb5083..be5b89fd30472 100644 --- a/src/Symfony/Component/Console/Descriptor/Text/ApplicationTextDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Text/ApplicationTextDescriptor.php @@ -27,10 +27,12 @@ class ApplicationTextDescriptor extends AbstractTextDescriptor /** * @param string|null $namespace + * @param bool $raw */ - public function __construct($namespace = null) + public function __construct($namespace = null, $raw = false) { $this->namespace = $namespace; + parent::__construct($raw); } /** diff --git a/src/Symfony/Component/Console/Descriptor/Text/CommandTextDescriptor.php b/src/Symfony/Component/Console/Descriptor/Text/CommandTextDescriptor.php new file mode 100644 index 0000000000000..b100dfe29b5f8 --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Text/CommandTextDescriptor.php @@ -0,0 +1,60 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Descriptor\Text; + +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputDefinition; + +/** + * @author Jean-François Simon + */ +class CommandTextDescriptor extends AbstractTextDescriptor +{ + /** + * {@inheritdoc} + */ + public function getRawText($object) + { + return strip_tags($this->getFormattedText($object)); + } + + /** + * {@inheritdoc} + */ + public function getFormattedText($object) + { + /** @var Command $object */ + $messages = array('Usage:', ' '.$object->getSynopsis(), ''); + + if ($object->getAliases()) { + $messages[] = 'Aliases: '.implode(', ', $object->getAliases()).''; + } + + $descriptor = new InputDefinitionTextDescriptor(); + $messages[] = $descriptor->getFormattedText($object->getDefinition()); + + if ($help = $object->getProcessedHelp()) { + $messages[] = 'Help:'; + $messages[] = ' '.str_replace("\n", "\n ", $help)."\n"; + } + + return implode("\n", $messages); + } + + /** + * {@inheritdoc} + */ + public function supports($object) + { + return $object instanceof Command; + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Text/InputArgumentTextDescriptor.php b/src/Symfony/Component/Console/Descriptor/Text/InputArgumentTextDescriptor.php new file mode 100644 index 0000000000000..96fd69c5bb556 --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Text/InputArgumentTextDescriptor.php @@ -0,0 +1,81 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Descriptor\Text; + +use Symfony\Component\Console\Input\InputArgument; + +/** + * @author Jean-François Simon + */ +class InputArgumentTextDescriptor extends AbstractTextDescriptor +{ + /** + * @var int|null + */ + private $nameWidth; + + /** + * @param string|null $nameWidth + * @param bool $raw + */ + public function __construct($nameWidth = null, $raw = false) + { + $this->nameWidth = $nameWidth; + parent::__construct($raw); + } + + /** + * {@inheritdoc} + */ + public function configure(array $options) + { + if (isset($options['name_width'])) { + $this->nameWidth = $options['name_width']; + } + + return parent::configure($options); + } + + /** + * {@inheritdoc} + */ + public function getRawText($object) + { + return strip_tags($this->getFormattedText($object)); + } + + /** + * {@inheritdoc} + */ + public function getFormattedText($object) + { + /** @var InputArgument $object */ + if (null !== $object->getDefault() && (!is_array($object->getDefault()) || count($object->getDefault()))) { + $default = sprintf(' (default: %s)', $this->formatDefaultValue($object->getDefault())); + } else { + $default = ''; + } + + $nameWidth = $this->nameWidth ?: strlen($object->getName()); + $description = str_replace("\n", "\n".str_repeat(' ', $nameWidth + 2), $object->getDescription()); + + return sprintf(" %-${nameWidth}s %s%s", $object->getName(), $description, $default); + } + + /** + * {@inheritdoc} + */ + public function supports($object) + { + return $object instanceof InputArgument; + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Text/InputDefinitionTextDescriptor.php b/src/Symfony/Component/Console/Descriptor/Text/InputDefinitionTextDescriptor.php new file mode 100644 index 0000000000000..2aa32a164c0b1 --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Text/InputDefinitionTextDescriptor.php @@ -0,0 +1,83 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Descriptor\Text; + +use Symfony\Component\Console\Input\InputDefinition; + +/** + * @author Jean-François Simon + */ +class InputDefinitionTextDescriptor extends AbstractTextDescriptor +{ + /** + * {@inheritdoc} + */ + public function getRawText($object) + { + return strip_tags($this->getFormattedText($object)); + } + + /** + * {@inheritdoc} + */ + public function getFormattedText($object) + { + // find the largest option or argument name + $nameWidth = 0; + + /** @var InputDefinition $object */ + foreach ($object->getOptions() as $option) { + $nameLength = strlen($option->getName()) + 2; + if ($option->getShortcut()) { + $nameLength += strlen($option->getShortcut()) + 3; + } + + $nameWidth = max($nameWidth, $nameLength); + } + + foreach ($object->getArguments() as $argument) { + $nameWidth = max($nameWidth, strlen($argument->getName())); + } + + ++$nameWidth; + + $text = array(); + + if ($object->getArguments()) { + $text[] = 'Arguments:'; + $descriptor = new InputArgumentTextDescriptor($nameWidth); + foreach ($object->getArguments() as $argument) { + $text[] = $descriptor->getFormattedText($argument); + } + $text[] = ''; + } + + if ($object->getOptions()) { + $text[] = 'Options:'; + $descriptor = new InputOptionTextDescriptor($nameWidth); + foreach ($object->getOptions() as $option) { + $text[] = $descriptor->getFormattedText($option); + } + $text[] = ''; + } + + return implode("\n", $text); + } + + /** + * {@inheritdoc} + */ + public function supports($object) + { + return $object instanceof InputDefinition; + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Text/InputOptionTextDescriptor.php b/src/Symfony/Component/Console/Descriptor/Text/InputOptionTextDescriptor.php new file mode 100644 index 0000000000000..c3daf3f9c90e7 --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/Text/InputOptionTextDescriptor.php @@ -0,0 +1,87 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Descriptor\Text; + +use Symfony\Component\Console\Input\InputOption; + +/** + * @author Jean-François Simon + */ +class InputOptionTextDescriptor extends AbstractTextDescriptor +{ + /** + * @var int|null + */ + private $nameWidth; + + /** + * @param string|null $nameWidth + * @param bool $raw + */ + public function __construct($nameWidth = null, $raw = false) + { + $this->nameWidth = $nameWidth; + parent::__construct($raw); + } + + /** + * {@inheritdoc} + */ + public function configure(array $options) + { + if (isset($options['name_width'])) { + $this->nameWidth = $options['name_width']; + } + + return parent::configure($options); + } + + /** + * {@inheritdoc} + */ + public function getRawText($object) + { + return strip_tags($this->getFormattedText($object)); + } + + /** + * {@inheritdoc} + */ + public function getFormattedText($object) + { + /** @var InputOption $object */ + if ($object->acceptValue() && null !== $object->getDefault() && (!is_array($object->getDefault()) || count($object->getDefault()))) { + $default = sprintf(' (default: %s)', $this->formatDefaultValue($object->getDefault())); + } else { + $default = ''; + } + + $nameWidth = $this->nameWidth ?: strlen($object->getName()); + $nameWithShortcutWidth = $nameWidth - strlen($object->getName()) - 2; + + return sprintf(" %s %-${nameWithShortcutWidth}s%s%s%s", + '--'.$object->getName(), + $object->getShortcut() ? sprintf('(-%s) ', $object->getShortcut()) : '', + str_replace("\n", "\n".str_repeat(' ', $nameWidth + 2), $object->getDescription()), + $default, + $object->isArray() ? ' (multiple values allowed)' : '' + ); + } + + /** + * {@inheritdoc} + */ + public function supports($object) + { + return $object instanceof InputOption; + } +} diff --git a/src/Symfony/Component/Console/Tests/Command/HelpCommandTest.php b/src/Symfony/Component/Console/Tests/Command/HelpCommandTest.php index c55c4ca03dbd0..a7f52da431c75 100644 --- a/src/Symfony/Component/Console/Tests/Command/HelpCommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/HelpCommandTest.php @@ -53,12 +53,13 @@ public function testExecuteForApplicationCommand() $this->assertRegExp('/list \[--format="\.\.\."\] \[--raw\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); } + public function testExecuteForApplicationCommandWithXmlOption() { $application = new Application(); $commandTester = new CommandTester($application->get('help')); - $commandTester->execute(array('command_name' => 'list', 'format' => 'xml')); + $commandTester->execute(array('command_name' => 'list', '--format' => 'xml')); $this->assertRegExp('/list \[--format="\.\.\."\] \[--raw\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); - $this->assertRegExp('/getDisplay(), '->execute() returns an XML help text if --xml is passed'); + $this->assertRegExp('/getDisplay(), '->execute() returns an XML help text if --format=xml is passed'); } } diff --git a/src/Symfony/Component/Console/Tests/Descriptor/Text/ApplicationTextDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/Text/ApplicationTextDescriptorTest.php new file mode 100644 index 0000000000000..5470744ca543a --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Descriptor/Text/ApplicationTextDescriptorTest.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Tests\Descriptor\Text; + +use Symfony\Component\Console\Descriptor\Text\ApplicationTextDescriptor; +use Symfony\Component\Console\Tests\Descriptor\AbstractDescriptorTest; +use Symfony\Component\Console\Tests\Descriptor\ObjectsProvider; + +class ApplicationTextDescriptorTest extends AbstractDescriptorTest +{ + protected function getDescriptor() + { + return new ApplicationTextDescriptor(); + } + + protected function getObjects() + { + return ObjectsProvider::getApplications(); + } +} diff --git a/src/Symfony/Component/Console/Tests/Descriptor/Text/CommandTextDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/Text/CommandTextDescriptorTest.php new file mode 100644 index 0000000000000..c5aeb838e1019 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Descriptor/Text/CommandTextDescriptorTest.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Tests\Descriptor\Text; + +use Symfony\Component\Console\Descriptor\Text\CommandTextDescriptor; +use Symfony\Component\Console\Tests\Descriptor\AbstractDescriptorTest; +use Symfony\Component\Console\Tests\Descriptor\ObjectsProvider; + +class CommandTextDescriptorTest extends AbstractDescriptorTest +{ + protected function getDescriptor() + { + return new CommandTextDescriptor(); + } + + protected function getObjects() + { + return ObjectsProvider::getCommands(); + } +} diff --git a/src/Symfony/Component/Console/Tests/Descriptor/Text/InputArgumentTextDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/Text/InputArgumentTextDescriptorTest.php new file mode 100644 index 0000000000000..0f48099b0a8a8 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Descriptor/Text/InputArgumentTextDescriptorTest.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Tests\Descriptor\Text; + +use Symfony\Component\Console\Descriptor\Text\InputArgumentTextDescriptor; +use Symfony\Component\Console\Tests\Descriptor\AbstractDescriptorTest; +use Symfony\Component\Console\Tests\Descriptor\ObjectsProvider; + +class InputArgumentTextDescriptorTest extends AbstractDescriptorTest +{ + protected function getDescriptor() + { + return new InputArgumentTextDescriptor(); + } + + protected function getObjects() + { + return ObjectsProvider::getInputArguments(); + } +} diff --git a/src/Symfony/Component/Console/Tests/Descriptor/Text/InputDefinitionTextDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/Text/InputDefinitionTextDescriptorTest.php new file mode 100644 index 0000000000000..9b710bf5e98d8 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Descriptor/Text/InputDefinitionTextDescriptorTest.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Tests\Descriptor\Text; + +use Symfony\Component\Console\Descriptor\Text\InputDefinitionTextDescriptor; +use Symfony\Component\Console\Tests\Descriptor\AbstractDescriptorTest; +use Symfony\Component\Console\Tests\Descriptor\ObjectsProvider; + +class InputDefinitionTextDescriptorTest extends AbstractDescriptorTest +{ + protected function getDescriptor() + { + return new InputDefinitionTextDescriptor(); + } + + protected function getObjects() + { + return ObjectsProvider::getInputDefinitions(); + } +} diff --git a/src/Symfony/Component/Console/Tests/Descriptor/Text/InputOptionTextDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/Text/InputOptionTextDescriptorTest.php new file mode 100644 index 0000000000000..3f0ceb798cb6b --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Descriptor/Text/InputOptionTextDescriptorTest.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Tests\Descriptor\Text; + +use Symfony\Component\Console\Descriptor\Text\InputOptionTextDescriptor; +use Symfony\Component\Console\Tests\Descriptor\AbstractDescriptorTest; +use Symfony\Component\Console\Tests\Descriptor\ObjectsProvider; + +class InputOptionTextDescriptorTest extends AbstractDescriptorTest +{ + protected function getDescriptor() + { + return new InputOptionTextDescriptor(); + } + + protected function getObjects() + { + return ObjectsProvider::getInputOptions(); + } +} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_1.txt new file mode 100644 index 0000000000000..5488ae7873827 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.txt @@ -0,0 +1,17 @@ +Console Tool + +Usage: + [options] command [arguments] + +Options: + --help -h Display this help message. + --quiet -q Do not output any message. + --verbose -v Increase verbosity of messages. + --version -V Display this application version. + --ansi Force ANSI output. + --no-ansi Disable ANSI output. + --no-interaction -n Do not ask any interactive question. + +Available commands: + help Displays help for a command + list Lists commands diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_2.txt new file mode 100644 index 0000000000000..a677c3fda9d13 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.txt @@ -0,0 +1,22 @@ +My Symfony application version v1.0 + +Usage: + [options] command [arguments] + +Options: + --help -h Display this help message. + --quiet -q Do not output any message. + --verbose -v Increase verbosity of messages. + --version -V Display this application version. + --ansi Force ANSI output. + --no-ansi Disable ANSI output. + --no-interaction -n Do not ask any interactive question. + +Available commands: + alias1 command 1 description + alias2 command 1 description + help Displays help for a command + list Lists commands +descriptor + descriptor:command1 command 1 description + descriptor:command2 command 2 description diff --git a/src/Symfony/Component/Console/Tests/Fixtures/command_1.txt b/src/Symfony/Component/Console/Tests/Fixtures/command_1.txt new file mode 100644 index 0000000000000..2375ac0e63d8d --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/command_1.txt @@ -0,0 +1,7 @@ +Usage: + descriptor:command1 + +Aliases: alias1, alias2 + +Help: + command 1 help diff --git a/src/Symfony/Component/Console/Tests/Fixtures/command_2.txt b/src/Symfony/Component/Console/Tests/Fixtures/command_2.txt new file mode 100644 index 0000000000000..1da9f3d29fa05 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/command_2.txt @@ -0,0 +1,11 @@ +Usage: + descriptor:command2 [-o|--option_name] argument_name + +Arguments: + argument_name + +Options: + --option_name (-o) + +Help: + command 2 help diff --git a/src/Symfony/Component/Console/Tests/Fixtures/command_2.txt~ b/src/Symfony/Component/Console/Tests/Fixtures/command_2.txt~ new file mode 100644 index 0000000000000..77e000213dd26 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/command_2.txt~ @@ -0,0 +1,12 @@ +Usage: + descriptor:command2 [-o|--option_name] argument_name + +Aliases: alias1, alias2 +Arguments: + argument_name + +Options: + --option_name (-o) + +Help: + command 2 help diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_argument_1.txt b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_1.txt new file mode 100644 index 0000000000000..111e5157f892d --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_1.txt @@ -0,0 +1 @@ + argument_name diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_argument_2.txt b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_2.txt new file mode 100644 index 0000000000000..9497b1ce01a96 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_2.txt @@ -0,0 +1 @@ + argument_name argument description diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_argument_3.txt b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_3.txt new file mode 100644 index 0000000000000..c421fc9117cad --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_3.txt @@ -0,0 +1 @@ + argument_name argument description (default: "default_value") diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_definition_1.txt b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_1.txt new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_definition_2.txt b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_2.txt new file mode 100644 index 0000000000000..0db9f66263a71 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_2.txt @@ -0,0 +1,2 @@ +Arguments: + argument_name diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_definition_3.txt b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_3.txt new file mode 100644 index 0000000000000..c6fb2ccc7b5b1 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_3.txt @@ -0,0 +1,2 @@ +Options: + --option_name (-o) diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_definition_4.txt b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_4.txt new file mode 100644 index 0000000000000..e17c61c3adf4b --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_4.txt @@ -0,0 +1,5 @@ +Arguments: + argument_name + +Options: + --option_name (-o) diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_definition_4.txt~ b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_4.txt~ new file mode 100644 index 0000000000000..1a530ffa2ef08 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_definition_4.txt~ @@ -0,0 +1,5 @@ +Arguments: + argument_name + +Options: + --option_name (-o) diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_1.txt b/src/Symfony/Component/Console/Tests/Fixtures/input_option_1.txt new file mode 100644 index 0000000000000..daf83d07ea748 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_1.txt @@ -0,0 +1 @@ + --option_name (-o) diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_2.txt b/src/Symfony/Component/Console/Tests/Fixtures/input_option_2.txt new file mode 100644 index 0000000000000..627e3c1ce5db8 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_2.txt @@ -0,0 +1 @@ + --option_name (-o) option description (default: "default_value") diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_3.txt b/src/Symfony/Component/Console/Tests/Fixtures/input_option_3.txt new file mode 100644 index 0000000000000..b88b12d2b3e70 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_3.txt @@ -0,0 +1 @@ + --option_name (-o) option description diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_4.txt b/src/Symfony/Component/Console/Tests/Fixtures/input_option_4.txt new file mode 100644 index 0000000000000..5dba5e6e87422 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_4.txt @@ -0,0 +1 @@ + --option_name (-o) option description (multiple values allowed) From 27aa872544b8ef0161dba00c9214cc40caff4a92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Wed, 10 Apr 2013 07:33:08 +0200 Subject: [PATCH 10/24] [Console] repaired tests --- .../Command/AbstractDescriptionCommand.php | 4 +- .../Console/Descriptor/CommandDescription.php | 85 +++++++++++++++++++ .../Descriptor/Json/CommandJsonDescriptor.php | 16 ++-- .../Markdown/CommandMarkdownDescriptor.php | 18 ++-- .../Text/AbstractTextDescriptor.php | 2 +- .../Descriptor/Text/CommandTextDescriptor.php | 10 ++- .../Descriptor/Xml/CommandXmlDescriptor.php | 17 ++-- .../Console/Helper/DescriptorHelper.php | 2 +- .../Console/Tests/Fixtures/application_1.json | 2 +- .../Console/Tests/Fixtures/application_1.md | 8 +- .../Console/Tests/Fixtures/application_1.xml | 8 +- .../Console/Tests/Fixtures/application_2.json | 2 +- .../Console/Tests/Fixtures/application_2.md | 8 +- .../Console/Tests/Fixtures/application_2.xml | 8 +- .../Tests/Fixtures/application_run2.txt | 11 +-- .../Tests/Fixtures/application_run3.txt | 20 ++--- 16 files changed, 157 insertions(+), 64 deletions(-) create mode 100644 src/Symfony/Component/Console/Descriptor/CommandDescription.php diff --git a/src/Symfony/Component/Console/Command/AbstractDescriptionCommand.php b/src/Symfony/Component/Console/Command/AbstractDescriptionCommand.php index ad0d75b46bd96..5c8597807f73b 100644 --- a/src/Symfony/Component/Console/Command/AbstractDescriptionCommand.php +++ b/src/Symfony/Component/Console/Command/AbstractDescriptionCommand.php @@ -39,8 +39,8 @@ protected function configure() protected function createDefinition() { return new InputDefinition(array( - new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output help in other formats'), - new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'), + new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output help in other formats.'), + new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list.'), )); } diff --git a/src/Symfony/Component/Console/Descriptor/CommandDescription.php b/src/Symfony/Component/Console/Descriptor/CommandDescription.php new file mode 100644 index 0000000000000..835914751a6b4 --- /dev/null +++ b/src/Symfony/Component/Console/Descriptor/CommandDescription.php @@ -0,0 +1,85 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Descriptor; + +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputDefinition; + +/** + * @author Jean-François Simon + */ +class CommandDescription +{ + /** + * @var Command + */ + private $command; + + /** + * @param Command $command + */ + public function __construct(Command $command) + { + $this->command = $command; + } + + /** + * @return string + */ + public function getName() + { + return $this->command->getName(); + } + + /** + * @return string + */ + public function getDescription() + { + return $this->command->getDescription(); + } + + /** + * @return array + */ + public function getAliases() + { + return $this->command->getAliases(); + } + + /** + * @return string + */ + public function getSynopsis() + { + return $this->command->getSynopsis(); + } + + /** + * @return string + */ + public function getHelp() + { + return $this->command->getProcessedHelp(); + } + + /** + * @return InputDefinition + */ + public function getDefinition() + { + $method = new \ReflectionMethod($this->command, 'getNativeDefinition'); + $method->setAccessible(true); + + return $method->invoke($this->command); + } +} diff --git a/src/Symfony/Component/Console/Descriptor/Json/CommandJsonDescriptor.php b/src/Symfony/Component/Console/Descriptor/Json/CommandJsonDescriptor.php index 85d35aa6cf21f..433b4aef66f35 100644 --- a/src/Symfony/Component/Console/Descriptor/Json/CommandJsonDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Json/CommandJsonDescriptor.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Console\Descriptor\Json; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Descriptor\CommandDescription; /** * @author Jean-François Simon @@ -24,15 +25,16 @@ class CommandJsonDescriptor extends AbstractJsonDescriptor public function getData($object) { $definitionDescriptor = new InputDefinitionJsonDescriptor(); - /** @var Command $object */ + $description = new CommandDescription($object); + return array( - 'name' => $object->getName(), - 'usage' => $object->getSynopsis(), - 'description' => $object->getDescription(), - 'help' => $object->getProcessedHelp(), - 'aliases' => $object->getAliases(), - 'definition' => $definitionDescriptor->getData($object->getDefinition()), + 'name' => $description->getName(), + 'usage' => $description->getSynopsis(), + 'description' => $description->getDescription(), + 'help' => $description->getHelp(), + 'aliases' => $description->getAliases(), + 'definition' => $definitionDescriptor->getData($description->getDefinition()), ); } diff --git a/src/Symfony/Component/Console/Descriptor/Markdown/CommandMarkdownDescriptor.php b/src/Symfony/Component/Console/Descriptor/Markdown/CommandMarkdownDescriptor.php index 4e8a509ccf9a0..ea3ff33ce8ee0 100644 --- a/src/Symfony/Component/Console/Descriptor/Markdown/CommandMarkdownDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Markdown/CommandMarkdownDescriptor.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Console\Descriptor\Markdown; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Descriptor\CommandDescription; /** * @author Jean-François Simon @@ -23,20 +24,19 @@ class CommandMarkdownDescriptor extends AbstractMarkdownDescriptor */ public function getDocument($object) { + /** @var Command $object */ + $description = new CommandDescription($object); $definitionDescriptor = new InputDefinitionMarkdownDescriptor(); - $object->getProcessedHelp(); - - /** @var Command $object */ return new Document\Document(array( - new Document\Title($object->getName(), 2), + new Document\Title($description->getName(), 2), new Document\UnorderedList(array( - 'Description: '.($object->getDescription() ?: ''), - 'Usage: `'.$object->getSynopsis().'`', - 'Aliases: '.(count($object->getAliases()) ? '`'.implode('`, `', $object->getAliases()).'`' : ''), + 'Description: '.($description->getDescription() ?: ''), + 'Usage: `'.$description->getSynopsis().'`', + 'Aliases: '.(count($description->getAliases()) ? '`'.implode('`, `', $description->getAliases()).'`' : ''), )), - new Document\Paragraph($object->getProcessedHelp()), - $definitionDescriptor->getDocument($object->getDefinition()), + new Document\Paragraph($description->getHelp()), + $definitionDescriptor->getDocument($description->getDefinition()), )); } diff --git a/src/Symfony/Component/Console/Descriptor/Text/AbstractTextDescriptor.php b/src/Symfony/Component/Console/Descriptor/Text/AbstractTextDescriptor.php index 57e7df01a4d7f..bd6bcecb1d977 100644 --- a/src/Symfony/Component/Console/Descriptor/Text/AbstractTextDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Text/AbstractTextDescriptor.php @@ -82,7 +82,7 @@ public function getFormat() */ public function useFormatting() { - return false; + return true; } protected function formatDefaultValue($default) diff --git a/src/Symfony/Component/Console/Descriptor/Text/CommandTextDescriptor.php b/src/Symfony/Component/Console/Descriptor/Text/CommandTextDescriptor.php index b100dfe29b5f8..3d31bb7afcde2 100644 --- a/src/Symfony/Component/Console/Descriptor/Text/CommandTextDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Text/CommandTextDescriptor.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Console\Descriptor\Text; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Descriptor\CommandDescription; use Symfony\Component\Console\Input\InputDefinition; /** @@ -33,16 +34,17 @@ public function getRawText($object) public function getFormattedText($object) { /** @var Command $object */ - $messages = array('Usage:', ' '.$object->getSynopsis(), ''); + $description = new CommandDescription($object); + $messages = array('Usage:', ' '.$description->getSynopsis(), ''); if ($object->getAliases()) { - $messages[] = 'Aliases: '.implode(', ', $object->getAliases()).''; + $messages[] = 'Aliases: '.implode(', ', $description->getAliases()).''; } $descriptor = new InputDefinitionTextDescriptor(); - $messages[] = $descriptor->getFormattedText($object->getDefinition()); + $messages[] = $descriptor->getFormattedText($description->getDefinition()); - if ($help = $object->getProcessedHelp()) { + if ($help = $description->getHelp()) { $messages[] = 'Help:'; $messages[] = ' '.str_replace("\n", "\n ", $help)."\n"; } diff --git a/src/Symfony/Component/Console/Descriptor/Xml/CommandXmlDescriptor.php b/src/Symfony/Component/Console/Descriptor/Xml/CommandXmlDescriptor.php index 21f8b45f966c8..abf9e424f94a1 100644 --- a/src/Symfony/Component/Console/Descriptor/Xml/CommandXmlDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Xml/CommandXmlDescriptor.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Console\Descriptor\Xml; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Descriptor\CommandDescription; /** * @author Jean-François Simon @@ -27,26 +28,28 @@ public function buildDocument(\DOMNode $parent, $object) $parent->appendChild($commandXML = $dom->createElement('command')); /** @var Command $object */ - $commandXML->setAttribute('id', $object->getName()); - $commandXML->setAttribute('name', $object->getName()); + $description = new CommandDescription($object); + + $commandXML->setAttribute('id', $description->getName()); + $commandXML->setAttribute('name', $description->getName()); $commandXML->appendChild($usageXML = $dom->createElement('usage')); - $usageXML->appendChild($dom->createTextNode(sprintf($object->getSynopsis(), ''))); + $usageXML->appendChild($dom->createTextNode(sprintf($description->getSynopsis(), ''))); $commandXML->appendChild($descriptionXML = $dom->createElement('description')); - $descriptionXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $object->getDescription()))); + $descriptionXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $description->getDescription()))); $commandXML->appendChild($helpXML = $dom->createElement('help')); - $helpXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $object->getProcessedHelp()))); + $helpXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $description->getHelp()))); $commandXML->appendChild($aliasesXML = $dom->createElement('aliases')); - foreach ($object->getAliases() as $alias) { + foreach ($description->getAliases() as $alias) { $aliasesXML->appendChild($aliasXML = $dom->createElement('alias')); $aliasXML->appendChild($dom->createTextNode($alias)); } $descriptor = new InputDefinitionXmlDescriptor(); - $descriptor->buildDocument($commandXML, $object->getDefinition()); + $descriptor->buildDocument($commandXML, $description->getDefinition()); } /** diff --git a/src/Symfony/Component/Console/Helper/DescriptorHelper.php b/src/Symfony/Component/Console/Helper/DescriptorHelper.php index c947f991a22cf..e960f9f65e71f 100644 --- a/src/Symfony/Component/Console/Helper/DescriptorHelper.php +++ b/src/Symfony/Component/Console/Helper/DescriptorHelper.php @@ -48,7 +48,7 @@ public function describe(OutputInterface $output, $object, $format = null, $raw { $format = $format ?: $this->provider->getDefaultFormat(); $descriptor = $this->provider->configure(array('raw_text' => $raw))->get($object, $format); - $type = $raw && $descriptor->useFormatting() ? OutputInterface::OUTPUT_NORMAL : OutputInterface::OUTPUT_RAW; + $type = !$raw && $descriptor->useFormatting() ? OutputInterface::OUTPUT_NORMAL : OutputInterface::OUTPUT_RAW; $output->writeln($descriptor->describe($object), $type); } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.json b/src/Symfony/Component/Console/Tests/Fixtures/application_1.json index 085989bd58cd0..b6d28b34f34ac 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_1.json +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.json @@ -1 +1 @@ -{"commands":[{"name":"help","usage":"help [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the --format<\/comment> option:\n\n php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false}}}},{"name":"list","usage":"list [--format=\"...\"] [--raw] [namespace]","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the --format<\/comment> option:\n\n php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php app\/console list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false}}}}],"namespaces":[{"id":"_global","commands":["help","list"]}]} +{"commands":[{"name":"help","usage":"help [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the --format<\/comment> option:\n\n php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats.","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list.","default":false}}}},{"name":"list","usage":"list [--format=\"...\"] [--raw] [namespace]","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the --format<\/comment> option:\n\n php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php app\/console list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats.","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list.","default":false}}}}],"namespaces":[{"id":"_global","commands":["help","list"]}]} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.md b/src/Symfony/Component/Console/Tests/Fixtures/application_1.md index 19fb2aa422ec0..73c54c1eebf03 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_1.md +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.md @@ -40,7 +40,7 @@ To display the list of available commands, please use the list comm * Accept value: yes * Is value required: yes * Is multiple: no -* Description: To output help in other formats +* Description: To output help in other formats. * Default: `NULL` **raw:** @@ -50,7 +50,7 @@ To display the list of available commands, please use the list comm * Accept value: no * Is value required: no * Is multiple: no -* Description: To output raw command list +* Description: To output raw command list. * Default: `false` list @@ -95,7 +95,7 @@ It's also possible to get raw list of commands (useful for embedding command run * Accept value: yes * Is value required: yes * Is multiple: no -* Description: To output help in other formats +* Description: To output help in other formats. * Default: `NULL` **raw:** @@ -105,5 +105,5 @@ It's also possible to get raw list of commands (useful for embedding command run * Accept value: no * Is value required: no * Is multiple: no -* Description: To output raw command list +* Description: To output raw command list. * Default: `false` diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml b/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml index 38ea50b126d80..75b589e5b1422 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml @@ -24,10 +24,10 @@ @@ -58,10 +58,10 @@ diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.json b/src/Symfony/Component/Console/Tests/Fixtures/application_2.json index f7a1386f021b7..38167cee4bfbb 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_2.json +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.json @@ -1 +1 @@ -{"commands":[{"name":"help","usage":"help [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the --format<\/comment> option:\n\n php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false}}}},{"name":"list","usage":"list [--format=\"...\"] [--raw] [namespace]","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the --format<\/comment> option:\n\n php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php app\/console list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false}}}},{"name":"descriptor:command1","usage":"descriptor:command1","description":"command 1 description","help":"command 1 help","aliases":["alias1","alias2"],"definition":{"arguments":[],"options":[]}},{"name":"descriptor:command2","usage":"descriptor:command2 [-o|--option_name] argument_name","description":"command 2 description","help":"command 2 help","aliases":[],"definition":{"arguments":{"argument_name":{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null}},"options":{"option_name":{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false}}}}],"namespaces":[{"id":"_global","commands":["alias1","alias2","help","list"]},{"id":"descriptor","commands":["descriptor:command1","descriptor:command2"]}]} +{"commands":[{"name":"help","usage":"help [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the --format<\/comment> option:\n\n php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats.","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list.","default":false}}}},{"name":"list","usage":"list [--format=\"...\"] [--raw] [namespace]","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the --format<\/comment> option:\n\n php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php app\/console list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats.","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list.","default":false}}}},{"name":"descriptor:command1","usage":"descriptor:command1","description":"command 1 description","help":"command 1 help","aliases":["alias1","alias2"],"definition":{"arguments":[],"options":[]}},{"name":"descriptor:command2","usage":"descriptor:command2 [-o|--option_name] argument_name","description":"command 2 description","help":"command 2 help","aliases":[],"definition":{"arguments":{"argument_name":{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null}},"options":{"option_name":{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false}}}}],"namespaces":[{"id":"_global","commands":["alias1","alias2","help","list"]},{"id":"descriptor","commands":["descriptor:command1","descriptor:command2"]}]} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.md b/src/Symfony/Component/Console/Tests/Fixtures/application_2.md index cd21bdd1aa7f7..98cbff1a9ee9f 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_2.md +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.md @@ -47,7 +47,7 @@ To display the list of available commands, please use the list comm * Accept value: yes * Is value required: yes * Is multiple: no -* Description: To output help in other formats +* Description: To output help in other formats. * Default: `NULL` **raw:** @@ -57,7 +57,7 @@ To display the list of available commands, please use the list comm * Accept value: no * Is value required: no * Is multiple: no -* Description: To output raw command list +* Description: To output raw command list. * Default: `false` list @@ -102,7 +102,7 @@ It's also possible to get raw list of commands (useful for embedding command run * Accept value: yes * Is value required: yes * Is multiple: no -* Description: To output help in other formats +* Description: To output help in other formats. * Default: `NULL` **raw:** @@ -112,7 +112,7 @@ It's also possible to get raw list of commands (useful for embedding command run * Accept value: no * Is value required: no * Is multiple: no -* Description: To output raw command list +* Description: To output raw command list. * Default: `false` descriptor:command1 diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.xml b/src/Symfony/Component/Console/Tests/Fixtures/application_2.xml index 2fda065c6fc83..0ccdaf3cb4ecf 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_2.xml +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.xml @@ -24,10 +24,10 @@ @@ -58,10 +58,10 @@ diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_run2.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_run2.txt index 8b17c7f6bb0f7..dc35636d6192e 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_run2.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_run2.txt @@ -1,5 +1,5 @@ Usage: - help [--xml] [command_name] + help [--format="..."] [--raw] [command_name] Arguments: command The command to execute @@ -7,6 +7,7 @@ Arguments: Options: --format To output help in other formats. + --raw To output raw command list. --help (-h) Display this help message. --quiet (-q) Do not output any message. --verbose (-v) Increase verbosity of messages. @@ -17,12 +18,12 @@ Options: Help: The help command displays help for a given command: - + php app/console help list - + You can also output the help in other formats by using the --format option: - + php app/console help --format=xml list - + To display the list of available commands, please use the list command. diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_run3.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_run3.txt index a203c737e4147..7f84cfcce9754 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_run3.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_run3.txt @@ -1,27 +1,27 @@ Usage: - list [--xml] [--raw] [namespace] + list [--format="..."] [--raw] [namespace] Arguments: namespace The namespace name Options: - --format To output help in other formats - --raw To output raw command list + --format To output help in other formats. + --raw To output raw command list. Help: The list command lists all commands: - + php app/console list - + You can also display the commands for a specific namespace: - + php app/console list test - + You can also output the information in other formats by using the --format option: - + php app/console list --format=xml - + It's also possible to get raw list of commands (useful for embedding command runner): - + php app/console list --raw From 30d88073111a460ff947955ebd35adc98951b50a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Sun, 14 Apr 2013 07:38:25 +0200 Subject: [PATCH 11/24] [Console] re-introduced asText & asXml methods to avoid BC break --- src/Symfony/Component/Console/Application.php | 43 ++++++ .../Component/Console/Command/Command.php | 39 ++++++ .../Xml/InputOptionXmlDescriptor.php | 2 +- .../Console/Input/InputDefinition.php | 41 ++++++ .../Console/Tests/ApplicationTest.php | 18 +++ .../Console/Tests/Command/CommandTest.php | 18 +++ .../Console/Tests/Fixtures/application_1.xml | 2 + .../Console/Tests/Fixtures/application_2.xml | 2 + .../Tests/Fixtures/application_astext1.txt | 20 +++ .../Tests/Fixtures/application_astext2.txt | 16 +++ .../Tests/Fixtures/application_asxml1.txt | 131 ++++++++++++++++++ .../Tests/Fixtures/application_asxml2.txt | 37 +++++ .../Console/Tests/Fixtures/command_astext.txt | 18 +++ .../Console/Tests/Fixtures/command_asxml.txt | 38 +++++ .../Tests/Fixtures/definition_astext.txt | 11 ++ .../Tests/Fixtures/definition_asxml.txt | 39 ++++++ .../Console/Tests/Fixtures/input_option_3.xml | 1 + .../Console/Tests/Fixtures/input_option_4.xml | 1 + .../Tests/Input/InputDefinitionTest.php | 28 ++++ 19 files changed, 504 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_astext1.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_astext2.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_asxml1.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_asxml2.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/command_astext.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/command_asxml.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/definition_astext.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/definition_asxml.txt diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 245bf254878a7..73e35b803f7ee 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Console; +use Symfony\Component\Console\Descriptor\Text\ApplicationTextDescriptor; +use Symfony\Component\Console\Descriptor\Xml\ApplicationXmlDescriptor; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Input\ArrayInput; @@ -680,6 +682,47 @@ public static function getAbbreviations($names) return $abbrevs; } + /** + * Returns a text representation of the Application. + * + * @param string $namespace An optional namespace name + * @param boolean $raw Whether to return raw command list + * + * @return string A string representing the Application + * + * @deprecated + */ + public function asText($namespace = null, $raw = false) + { + $descriptor = new ApplicationTextDescriptor($namespace, $raw); + + return $descriptor->describe($this); + } + + /** + * Returns an XML representation of the Application. + * + * @param string $namespace An optional namespace name + * @param Boolean $asDom Whether to return a DOM or an XML string + * + * @return string|\DOMDocument An XML string representing the Application + * + * @deprecated + */ + public function asXml($namespace = null, $asDom = false) + { + $descriptor = new ApplicationXmlDescriptor($namespace); + + if ($asDom) { + $dom = new \DOMDocument('1.0', 'UTF-8'); + $descriptor->buildDocument($dom, $this); + + return $dom; + } + + return $descriptor->describe($this); + } + /** * Renders a caught exception. * diff --git a/src/Symfony/Component/Console/Command/Command.php b/src/Symfony/Component/Console/Command/Command.php index 870a65b548aff..86ac27e6b2bb2 100644 --- a/src/Symfony/Component/Console/Command/Command.php +++ b/src/Symfony/Component/Console/Command/Command.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Console\Command; +use Symfony\Component\Console\Descriptor\Text\CommandTextDescriptor; +use Symfony\Component\Console\Descriptor\Xml\CommandXmlDescriptor; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; @@ -555,6 +557,43 @@ public function getHelper($name) return $this->helperSet->get($name); } + /** + * Returns a text representation of the command. + * + * @return string A string representing the command + * + * @deprecated + */ + public function asText() + { + $descriptor = new CommandTextDescriptor(); + + return $descriptor->describe($this); + } + + /** + * Returns an XML representation of the command. + * + * @param Boolean $asDom Whether to return a DOM or an XML string + * + * @return string|\DOMDocument An XML string representing the command + * + * @deprecated + */ + public function asXml($asDom = false) + { + $descriptor = new CommandXmlDescriptor(); + + if ($asDom) { + $dom = new \DOMDocument('1.0', 'UTF-8'); + $descriptor->buildDocument($dom, $this); + + return $dom; + } + + return $descriptor->describe($this); + } + private function validateName($name) { if (!preg_match('/^[^\:]+(\:[^\:]+)*$/', $name)) { diff --git a/src/Symfony/Component/Console/Descriptor/Xml/InputOptionXmlDescriptor.php b/src/Symfony/Component/Console/Descriptor/Xml/InputOptionXmlDescriptor.php index 40870b8d41e1b..f11a7f26f728e 100644 --- a/src/Symfony/Component/Console/Descriptor/Xml/InputOptionXmlDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/Xml/InputOptionXmlDescriptor.php @@ -37,9 +37,9 @@ public function buildDocument(\DOMNode $parent, $object) if ($object->acceptValue()) { $defaults = is_array($object->getDefault()) ? $object->getDefault() : (is_bool($object->getDefault()) ? array(var_export($object->getDefault(), true)) : ($object->getDefault() ? array($object->getDefault()) : array())); + $objectXML->appendChild($defaultsXML = $dom->createElement('defaults')); if (!empty($defaults)) { - $objectXML->appendChild($defaultsXML = $dom->createElement('defaults')); foreach ($defaults as $default) { $defaultsXML->appendChild($defaultXML = $dom->createElement('default')); $defaultXML->appendChild($dom->createTextNode($default)); diff --git a/src/Symfony/Component/Console/Input/InputDefinition.php b/src/Symfony/Component/Console/Input/InputDefinition.php index 4c5dcf3b574dd..18617a0e95e93 100644 --- a/src/Symfony/Component/Console/Input/InputDefinition.php +++ b/src/Symfony/Component/Console/Input/InputDefinition.php @@ -11,6 +11,9 @@ namespace Symfony\Component\Console\Input; +use Symfony\Component\Console\Descriptor\Text\InputDefinitionTextDescriptor; +use Symfony\Component\Console\Descriptor\Xml\InputDefinitionXmlDescriptor; + /** * A InputDefinition represents a set of valid command line arguments and options. * @@ -399,4 +402,42 @@ public function getSynopsis() return implode(' ', $elements); } + + + /** + * Returns a textual representation of the InputDefinition. + * + * @return string A string representing the InputDefinition + * + * @deprecated + */ + public function asText() + { + $descriptor = new InputDefinitionTextDescriptor(); + + return $descriptor->describe($this); + } + + /** + * Returns an XML representation of the InputDefinition. + * + * @param Boolean $asDom Whether to return a DOM or an XML string + * + * @return string|\DOMDocument An XML string representing the InputDefinition + * + * @deprecated + */ + public function asXml($asDom = false) + { + $descriptor = new InputDefinitionXmlDescriptor(); + + if ($asDom) { + $dom = new \DOMDocument('1.0', 'UTF-8'); + $descriptor->buildDocument($dom, $this); + + return $dom; + } + + return $descriptor->describe($this); + } } diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index 783d364dc1d1a..f2614bfa37e26 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -392,6 +392,24 @@ public function testSetCatchExceptions() } } + public function testAsText() + { + $application = new Application(); + $application->add(new \FooCommand); + $this->ensureStaticCommandHelp($application); + $this->assertStringEqualsFile(self::$fixturesPath.'/application_astext1.txt', $this->normalizeLineBreaks($application->asText()), '->asText() returns a text representation of the application'); + $this->assertStringEqualsFile(self::$fixturesPath.'/application_astext2.txt', $this->normalizeLineBreaks($application->asText('foo')), '->asText() returns a text representation of the application'); + } + + public function testAsXml() + { + $application = new Application(); + $application->add(new \FooCommand); + $this->ensureStaticCommandHelp($application); + $this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/application_asxml1.txt', $application->asXml(), '->asXml() returns an XML representation of the application'); + $this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/application_asxml2.txt', $application->asXml('foo'), '->asXml() returns an XML representation of the application'); + } + public function testRenderException() { $application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth')); diff --git a/src/Symfony/Component/Console/Tests/Command/CommandTest.php b/src/Symfony/Component/Console/Tests/Command/CommandTest.php index 3aa990f9be083..acbe2ea10ce38 100644 --- a/src/Symfony/Component/Console/Tests/Command/CommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/CommandTest.php @@ -280,4 +280,22 @@ public function callableMethodCommand(InputInterface $input, OutputInterface $ou { $output->writeln('from the code...'); } + + public function testAsText() + { + $command = new \TestCommand(); + $command->setApplication(new Application()); + $tester = new CommandTester($command); + $tester->execute(array('command' => $command->getName())); + $this->assertStringEqualsFile(self::$fixturesPath.'/command_astext.txt', $command->asText(), '->asText() returns a text representation of the command'); + } + + public function testAsXml() + { + $command = new \TestCommand(); + $command->setApplication(new Application()); + $tester = new CommandTester($command); + $tester->execute(array('command' => $command->getName())); + $this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/command_asxml.txt', $command->asXml(), '->asXml() returns an XML representation of the command'); + } } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml b/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml index 75b589e5b1422..221cc33e93026 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml @@ -25,6 +25,7 @@ diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.json b/src/Symfony/Component/Console/Tests/Fixtures/application_2.json index 38167cee4bfbb..b4635ab414db6 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_2.json +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.json @@ -1 +1 @@ -{"commands":[{"name":"help","usage":"help [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the --format<\/comment> option:\n\n php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats.","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list.","default":false}}}},{"name":"list","usage":"list [--format=\"...\"] [--raw] [namespace]","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the --format<\/comment> option:\n\n php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php app\/console list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats.","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list.","default":false}}}},{"name":"descriptor:command1","usage":"descriptor:command1","description":"command 1 description","help":"command 1 help","aliases":["alias1","alias2"],"definition":{"arguments":[],"options":[]}},{"name":"descriptor:command2","usage":"descriptor:command2 [-o|--option_name] argument_name","description":"command 2 description","help":"command 2 help","aliases":[],"definition":{"arguments":{"argument_name":{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null}},"options":{"option_name":{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false}}}}],"namespaces":[{"id":"_global","commands":["alias1","alias2","help","list"]},{"id":"descriptor","commands":["descriptor:command1","descriptor:command2"]}]} +{"commands":[{"name":"help","usage":"help [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the --format<\/comment> option:\n\n php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats.","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list.","default":false},"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message.","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message.","default":false},"verbose":{"name":"--verbose","shortcut":"-v","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase verbosity of messages.","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version.","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output.","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output.","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question.","default":false}}}},{"name":"list","usage":"list [--format=\"...\"] [--raw] [namespace]","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the --format<\/comment> option:\n\n php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php app\/console list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats.","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list.","default":false}}}},{"name":"descriptor:command1","usage":"descriptor:command1","description":"command 1 description","help":"command 1 help","aliases":["alias1","alias2"],"definition":{"arguments":[],"options":{"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message.","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message.","default":false},"verbose":{"name":"--verbose","shortcut":"-v","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase verbosity of messages.","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version.","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output.","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output.","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question.","default":false}}}},{"name":"descriptor:command2","usage":"descriptor:command2 [-o|--option_name] argument_name","description":"command 2 description","help":"command 2 help","aliases":[],"definition":{"arguments":{"argument_name":{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null}},"options":{"option_name":{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false},"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message.","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message.","default":false},"verbose":{"name":"--verbose","shortcut":"-v","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase verbosity of messages.","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version.","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output.","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output.","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question.","default":false}}}}],"namespaces":[{"id":"_global","commands":["alias1","alias2","help","list"]},{"id":"descriptor","commands":["descriptor:command1","descriptor:command2"]}]} \ No newline at end of file diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.md b/src/Symfony/Component/Console/Tests/Fixtures/application_2.md index 98cbff1a9ee9f..c5ddb45675692 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_2.md +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.md @@ -60,6 +60,76 @@ To display the list of available commands, please use the list comm * Description: To output raw command list. * Default: `false` +**help:** + +* Name: `--help` +* Shortcut: `-h` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Display this help message. +* Default: `false` + +**quiet:** + +* Name: `--quiet` +* Shortcut: `-q` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Do not output any message. +* Default: `false` + +**verbose:** + +* Name: `--verbose` +* Shortcut: `-v` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Increase verbosity of messages. +* Default: `false` + +**version:** + +* Name: `--version` +* Shortcut: `-V` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Display this application version. +* Default: `false` + +**ansi:** + +* Name: `--ansi` +* Shortcut: +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Force ANSI output. +* Default: `false` + +**no-ansi:** + +* Name: `--no-ansi` +* Shortcut: +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Disable ANSI output. +* Default: `false` + +**no-interaction:** + +* Name: `--no-interaction` +* Shortcut: `-n` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Do not ask any interactive question. +* Default: `false` + list ---- @@ -124,6 +194,78 @@ descriptor:command1 command 1 help +### Options: + +**help:** + +* Name: `--help` +* Shortcut: `-h` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Display this help message. +* Default: `false` + +**quiet:** + +* Name: `--quiet` +* Shortcut: `-q` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Do not output any message. +* Default: `false` + +**verbose:** + +* Name: `--verbose` +* Shortcut: `-v` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Increase verbosity of messages. +* Default: `false` + +**version:** + +* Name: `--version` +* Shortcut: `-V` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Display this application version. +* Default: `false` + +**ansi:** + +* Name: `--ansi` +* Shortcut: +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Force ANSI output. +* Default: `false` + +**no-ansi:** + +* Name: `--no-ansi` +* Shortcut: +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Disable ANSI output. +* Default: `false` + +**no-interaction:** + +* Name: `--no-interaction` +* Shortcut: `-n` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Do not ask any interactive question. +* Default: `false` + descriptor:command2 ------------------- @@ -154,3 +296,73 @@ command 2 help * Is multiple: no * Description: * Default: `false` + +**help:** + +* Name: `--help` +* Shortcut: `-h` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Display this help message. +* Default: `false` + +**quiet:** + +* Name: `--quiet` +* Shortcut: `-q` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Do not output any message. +* Default: `false` + +**verbose:** + +* Name: `--verbose` +* Shortcut: `-v` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Increase verbosity of messages. +* Default: `false` + +**version:** + +* Name: `--version` +* Shortcut: `-V` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Display this application version. +* Default: `false` + +**ansi:** + +* Name: `--ansi` +* Shortcut: +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Force ANSI output. +* Default: `false` + +**no-ansi:** + +* Name: `--no-ansi` +* Shortcut: +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Disable ANSI output. +* Default: `false` + +**no-interaction:** + +* Name: `--no-interaction` +* Shortcut: `-n` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Do not ask any interactive question. +* Default: `false` diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.xml b/src/Symfony/Component/Console/Tests/Fixtures/application_2.xml index 6cd652bfcf494..8ee61bbfe44fd 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_2.xml +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.xml @@ -30,6 +30,27 @@ + + + + + + + @@ -76,7 +97,29 @@ alias2 - + + + + + + + + + descriptor:command2 [-o|--option_name] argument_name @@ -93,6 +136,27 @@ + + + + + + + diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_asxml1.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_asxml1.txt index efa4fbff649d4..50a63e20626ad 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_asxml1.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_asxml1.txt @@ -30,6 +30,9 @@ + From ef6d8ba93a3b7526e28be1740fe7dc884a0fd4d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Sun, 14 Apr 2013 08:15:39 +0200 Subject: [PATCH 13/24] [Console] simplified description commands --- .../Command/AbstractDescriptionCommand.php | 58 ------------------- .../Component/Console/Command/HelpCommand.php | 23 +++----- .../Component/Console/Command/ListCommand.php | 19 +++--- .../Console/Helper/DescriptorHelper.php | 4 +- .../Console/Tests/Fixtures/application_1.json | 2 +- .../Console/Tests/Fixtures/application_1.md | 4 +- .../Console/Tests/Fixtures/application_1.xml | 4 +- .../Console/Tests/Fixtures/application_2.json | 2 +- .../Console/Tests/Fixtures/application_2.md | 4 +- .../Console/Tests/Fixtures/application_2.xml | 4 +- .../Tests/Fixtures/application_asxml1.txt | 4 +- .../Tests/Fixtures/application_run2.txt | 2 +- .../Tests/Fixtures/application_run3.txt | 2 +- 13 files changed, 36 insertions(+), 96 deletions(-) delete mode 100644 src/Symfony/Component/Console/Command/AbstractDescriptionCommand.php diff --git a/src/Symfony/Component/Console/Command/AbstractDescriptionCommand.php b/src/Symfony/Component/Console/Command/AbstractDescriptionCommand.php deleted file mode 100644 index 5c8597807f73b..0000000000000 --- a/src/Symfony/Component/Console/Command/AbstractDescriptionCommand.php +++ /dev/null @@ -1,58 +0,0 @@ - - */ -abstract class AbstractDescriptionCommand extends Command -{ - /** - * @var DescriptorProvider - */ - private $provider; - - /** - * {@inheritdoc} - */ - protected function configure() - { - $this->provider = new DescriptorProvider(); - $this->setDefinition($this->createDefinition()); - } - - /** - * Creates command definition. - * - * @return InputDefinition - */ - protected function createDefinition() - { - return new InputDefinition(array( - new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output help in other formats.'), - new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list.'), - )); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - if (null === $this->getHelperSet()) { - $this->setHelperSet(new HelperSet()); - } - - $this->getHelperSet()->set(new DescriptorHelper($this->provider)); - } -} diff --git a/src/Symfony/Component/Console/Command/HelpCommand.php b/src/Symfony/Component/Console/Command/HelpCommand.php index 3623b0241f0b6..de339f4fb25f1 100644 --- a/src/Symfony/Component/Console/Command/HelpCommand.php +++ b/src/Symfony/Component/Console/Command/HelpCommand.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Console\Command; +use Symfony\Component\Console\Helper\DescriptorHelper; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; @@ -21,7 +22,7 @@ * * @author Fabien Potencier */ -class HelpCommand extends AbstractDescriptionCommand +class HelpCommand extends Command { private $command; @@ -36,6 +37,11 @@ protected function configure() $this ->setName('help') ->setDescription('Displays help for a command') + ->setDefinition(array( + new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output help in other formats.'), + new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command help.'), + new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'), + )) ->setHelp(<<%command.name% command displays help for a given command: @@ -61,17 +67,6 @@ public function setCommand(Command $command) $this->command = $command; } - /** - * {@inheritdoc} - */ - protected function createDefinition() - { - $definition = parent::createDefinition(); - $definition->addArgument(new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help')); - - return $definition; - } - /** * {@inheritdoc} */ @@ -81,8 +76,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->command = $this->getApplication()->find($input->getArgument('command_name')); } - parent::execute($input, $output); - $this->getHelper('descriptor')->describe($output, $this->command, $input->getOption('format'), $input->getOption('raw')); + $helper = new DescriptorHelper(); + $helper->describe($output, $this->command, $input->getOption('format'), $input->getOption('raw')); $this->command = null; } } diff --git a/src/Symfony/Component/Console/Command/ListCommand.php b/src/Symfony/Component/Console/Command/ListCommand.php index 7c6176d029c68..404219e9ae700 100644 --- a/src/Symfony/Component/Console/Command/ListCommand.php +++ b/src/Symfony/Component/Console/Command/ListCommand.php @@ -11,7 +11,9 @@ namespace Symfony\Component\Console\Command; +use Symfony\Component\Console\Helper\DescriptorHelper; use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -21,7 +23,7 @@ * * @author Fabien Potencier */ -class ListCommand extends AbstractDescriptionCommand +class ListCommand extends Command { /** * {@inheritdoc} @@ -33,6 +35,7 @@ protected function configure() $this ->setName('list') ->setDescription('Lists commands') + ->setDefinition($this->createDefinition()) ->setHelp(<<%command.name% command lists all commands: @@ -59,10 +62,11 @@ protected function configure() */ protected function createDefinition() { - $definition = parent::createDefinition(); - $definition->addArgument(new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name')); - - return $definition; + return new InputDefinition(array( + new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output list in other formats.'), + new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list.'), + new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'), + )); } /** @@ -78,8 +82,7 @@ protected function getNativeDefinition() */ protected function execute(InputInterface $input, OutputInterface $output) { - parent::execute($input, $output); - - $this->getHelper('descriptor')->describe($output, $this->getApplication(), $input->getOption('format'), $input->getOption('raw')); + $helper = new DescriptorHelper(); + $helper->describe($output, $this->getApplication(), $input->getOption('format'), $input->getOption('raw')); } } diff --git a/src/Symfony/Component/Console/Helper/DescriptorHelper.php b/src/Symfony/Component/Console/Helper/DescriptorHelper.php index e960f9f65e71f..ed8dc44fb7a29 100644 --- a/src/Symfony/Component/Console/Helper/DescriptorHelper.php +++ b/src/Symfony/Component/Console/Helper/DescriptorHelper.php @@ -31,9 +31,9 @@ class DescriptorHelper extends Helper * * @param DescriptorProvider $provider */ - public function __construct(DescriptorProvider $provider) + public function __construct(DescriptorProvider $provider = null) { - $this->provider = $provider; + $this->provider = $provider ?: new DescriptorProvider(); } /** diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.json b/src/Symfony/Component/Console/Tests/Fixtures/application_1.json index 1768d63740d03..ef49cbe2570c9 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_1.json +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.json @@ -1 +1 @@ -{"commands":[{"name":"help","usage":"help [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the --format<\/comment> option:\n\n php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats.","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list.","default":false},"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message.","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message.","default":false},"verbose":{"name":"--verbose","shortcut":"-v","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase verbosity of messages.","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version.","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output.","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output.","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question.","default":false}}}},{"name":"list","usage":"list [--format=\"...\"] [--raw] [namespace]","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the --format<\/comment> option:\n\n php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php app\/console list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats.","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list.","default":false}}}}],"namespaces":[{"id":"_global","commands":["help","list"]}]} \ No newline at end of file +{"commands":[{"name":"help","usage":"help [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the --format<\/comment> option:\n\n php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats.","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command help.","default":false},"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message.","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message.","default":false},"verbose":{"name":"--verbose","shortcut":"-v","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase verbosity of messages.","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version.","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output.","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output.","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question.","default":false}}}},{"name":"list","usage":"list [--format=\"...\"] [--raw] [namespace]","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the --format<\/comment> option:\n\n php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php app\/console list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output list in other formats.","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list.","default":false}}}}],"namespaces":[{"id":"_global","commands":["help","list"]}]} \ No newline at end of file diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.md b/src/Symfony/Component/Console/Tests/Fixtures/application_1.md index 6d2c3e741b388..d8b12f18f558d 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_1.md +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.md @@ -50,7 +50,7 @@ To display the list of available commands, please use the list comm * Accept value: no * Is value required: no * Is multiple: no -* Description: To output raw command list. +* Description: To output raw command help. * Default: `false` **help:** @@ -165,7 +165,7 @@ It's also possible to get raw list of commands (useful for embedding command run * Accept value: yes * Is value required: yes * Is multiple: no -* Description: To output help in other formats. +* Description: To output list in other formats. * Default: `NULL` **raw:** diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml b/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml index c0fcadf9dd7cc..31465958323a0 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml @@ -28,7 +28,7 @@ command displays help for a given command: diff --git a/src/Symfony/Component/Console/Command/ListCommand.php b/src/Symfony/Component/Console/Command/ListCommand.php index d1c8d2b5434cf..4b3374756e593 100644 --- a/src/Symfony/Component/Console/Command/ListCommand.php +++ b/src/Symfony/Component/Console/Command/ListCommand.php @@ -13,10 +13,10 @@ use Symfony\Component\Console\Helper\DescriptorHelper; use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Input\InputDefinition; /** * ListCommand displays the list of all available commands for the application. @@ -32,8 +32,8 @@ protected function configure() { $this ->setName('list') - ->setDescription('Lists commands') ->setDefinition($this->createDefinition()) + ->setDescription('Lists commands') ->setHelp(<<%command.name% command lists all commands: @@ -55,19 +55,6 @@ protected function configure() ; } - /** - * {@inheritdoc} - */ - private function createDefinition() - { - return new InputDefinition(array( - new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output list in other formats.'), - new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list.'), - new InputOption('xml', null, InputOption::VALUE_NONE, 'To output list as XML.'), - new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'), - )); - } - /** * {@inheritdoc} */ @@ -88,4 +75,17 @@ protected function execute(InputInterface $input, OutputInterface $output) $helper = new DescriptorHelper(); $helper->describe($output, $this->getApplication(), $input->getOption('format'), $input->getOption('raw')); } + + /** + * {@inheritdoc} + */ + private function createDefinition() + { + return new InputDefinition(array( + new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output list in other formats.'), + new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list.'), + new InputOption('xml', null, InputOption::VALUE_NONE, 'To output list as XML.'), + new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'), + )); + } } From cbb8105b0d94601d729897659f1a992393e444f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Tue, 23 Apr 2013 17:12:24 +0200 Subject: [PATCH 24/24] [Console] moved commands arguments --- .../Component/Console/Command/HelpCommand.php | 6 +-- .../Component/Console/Command/ListCommand.php | 6 +-- .../Console/Helper/DescriptorHelper.php | 1 - .../Console/Input/InputDefinition.php | 1 - .../Console/Tests/Command/HelpCommandTest.php | 8 +-- .../Console/Tests/Fixtures/application_1.json | 2 +- .../Console/Tests/Fixtures/application_1.md | 54 +++++++++---------- .../Console/Tests/Fixtures/application_1.xml | 26 ++++----- .../Console/Tests/Fixtures/application_2.json | 2 +- .../Console/Tests/Fixtures/application_2.md | 54 +++++++++---------- .../Console/Tests/Fixtures/application_2.xml | 26 ++++----- .../Tests/Fixtures/application_asxml1.txt | 26 ++++----- .../Fixtures/application_renderexception2.txt | 2 +- .../Tests/Fixtures/application_run2.txt | 8 +-- .../Tests/Fixtures/application_run3.txt | 8 +-- 15 files changed, 114 insertions(+), 116 deletions(-) diff --git a/src/Symfony/Component/Console/Command/HelpCommand.php b/src/Symfony/Component/Console/Command/HelpCommand.php index 46bb3005de5ae..2aa933ea0f7a7 100644 --- a/src/Symfony/Component/Console/Command/HelpCommand.php +++ b/src/Symfony/Component/Console/Command/HelpCommand.php @@ -37,9 +37,9 @@ protected function configure() ->setName('help') ->setDefinition(array( new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'), - new InputOption('xml', null, InputOption::VALUE_NONE, 'To output help as XML.'), - new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output help in other formats.'), - new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command help.'), + new InputOption('xml', null, InputOption::VALUE_NONE, 'To output help as XML'), + new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output help in other formats'), + new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command help'), )) ->setDescription('Displays help for a command') ->setHelp(<<setApplication(new Application()); $commandTester = new CommandTester($command); $commandTester->execute(array('command_name' => 'li')); - $this->assertRegExp('/list \[--format="\.\.\."\] \[--raw\] \[--xml\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command alias'); + $this->assertRegExp('/list \[--xml\] \[--raw\] \[--format="\.\.\."\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command alias'); } public function testExecuteForCommand() @@ -33,7 +33,7 @@ public function testExecuteForCommand() $commandTester = new CommandTester($command); $command->setCommand(new ListCommand()); $commandTester->execute(array()); - $this->assertRegExp('/list \[--format="\.\.\."\] \[--raw\] \[--xml\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); + $this->assertRegExp('/list \[--xml\] \[--raw\] \[--format="\.\.\."\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); } public function testExecuteForCommandWithXmlOption() @@ -50,7 +50,7 @@ public function testExecuteForApplicationCommand() $application = new Application(); $commandTester = new CommandTester($application->get('help')); $commandTester->execute(array('command_name' => 'list')); - $this->assertRegExp('/list \[--format="\.\.\."\] \[--raw\] \[--xml\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); + $this->assertRegExp('/list \[--xml\] \[--raw\] \[--format="\.\.\."\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); } @@ -59,7 +59,7 @@ public function testExecuteForApplicationCommandWithXmlOption() $application = new Application(); $commandTester = new CommandTester($application->get('help')); $commandTester->execute(array('command_name' => 'list', '--format' => 'xml')); - $this->assertRegExp('/list \[--format="\.\.\."\] \[--raw\] \[--xml\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); + $this->assertRegExp('/list \[--xml\] \[--raw\] \[--format="\.\.\."\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); $this->assertRegExp('/getDisplay(), '->execute() returns an XML help text if --format=xml is passed'); } } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.json b/src/Symfony/Component/Console/Tests/Fixtures/application_1.json index 394724d98818a..116e125ecfa98 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_1.json +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.json @@ -1 +1 @@ -{"commands":[{"name":"help","usage":"help [--format=\"...\"] [--raw] [--xml] [command_name]","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the --format<\/comment> option:\n\n php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats.","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command help.","default":false},"xml":{"name":"--xml","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output help as XML.","default":false},"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message.","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message.","default":false},"verbose":{"name":"--verbose","shortcut":"-v","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase verbosity of messages.","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version.","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output.","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output.","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question.","default":false}}}},{"name":"list","usage":"list [--format=\"...\"] [--raw] [--xml] [namespace]","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the --format<\/comment> option:\n\n php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php app\/console list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output list in other formats.","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list.","default":false},"xml":{"name":"--xml","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output list as XML.","default":false}}}}],"namespaces":[{"id":"_global","commands":["help","list"]}]} \ No newline at end of file +{"commands":[{"name":"help","usage":"help [--xml] [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the --format<\/comment> option:\n\n php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"xml":{"name":"--xml","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output help as XML","default":false},"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command help","default":false},"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message.","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message.","default":false},"verbose":{"name":"--verbose","shortcut":"-v","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase verbosity of messages.","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version.","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output.","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output.","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question.","default":false}}}},{"name":"list","usage":"list [--xml] [--raw] [--format=\"...\"] [namespace]","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the --format<\/comment> option:\n\n php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php app\/console list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"xml":{"name":"--xml","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output list as XML","default":false},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false},"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output list in other formats","default":null}}}}],"namespaces":[{"id":"_global","commands":["help","list"]}]} \ No newline at end of file diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.md b/src/Symfony/Component/Console/Tests/Fixtures/application_1.md index 851faaa92caba..ca564e45ca1b2 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_1.md +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.md @@ -8,7 +8,7 @@ help ---- * Description: Displays help for a command -* Usage: `help [--format="..."] [--raw] [--xml] [command_name]` +* Usage: `help [--xml] [--format="..."] [--raw] [command_name]` * Aliases: The help command displays help for a given command: @@ -33,6 +33,16 @@ To display the list of available commands, please use the list comm ### Options: +**xml:** + +* Name: `--xml` +* Shortcut: +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: To output help as XML +* Default: `false` + **format:** * Name: `--format` @@ -40,7 +50,7 @@ To display the list of available commands, please use the list comm * Accept value: yes * Is value required: yes * Is multiple: no -* Description: To output help in other formats. +* Description: To output help in other formats * Default: `NULL` **raw:** @@ -50,17 +60,7 @@ To display the list of available commands, please use the list comm * Accept value: no * Is value required: no * Is multiple: no -* Description: To output raw command help. -* Default: `false` - -**xml:** - -* Name: `--xml` -* Shortcut: -* Accept value: no -* Is value required: no -* Is multiple: no -* Description: To output help as XML. +* Description: To output raw command help * Default: `false` **help:** @@ -137,7 +137,7 @@ list ---- * Description: Lists commands -* Usage: `list [--format="..."] [--raw] [--xml] [namespace]` +* Usage: `list [--xml] [--raw] [--format="..."] [namespace]` * Aliases: The list command lists all commands: @@ -168,15 +168,15 @@ It's also possible to get raw list of commands (useful for embedding command run ### Options: -**format:** +**xml:** -* Name: `--format` +* Name: `--xml` * Shortcut: -* Accept value: yes -* Is value required: yes +* Accept value: no +* Is value required: no * Is multiple: no -* Description: To output list in other formats. -* Default: `NULL` +* Description: To output list as XML +* Default: `false` **raw:** @@ -185,15 +185,15 @@ It's also possible to get raw list of commands (useful for embedding command run * Accept value: no * Is value required: no * Is multiple: no -* Description: To output raw command list. +* Description: To output raw command list * Default: `false` -**xml:** +**format:** -* Name: `--xml` +* Name: `--format` * Shortcut: -* Accept value: no -* Is value required: no +* Accept value: yes +* Is value required: yes * Is multiple: no -* Description: To output list as XML. -* Default: `false` +* Description: To output list in other formats +* Default: `NULL` diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml b/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml index 9d882568b97f1..ba5decadfe781 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml @@ -2,7 +2,7 @@ - help [--format="..."] [--raw] [--xml] [command_name] + help [--xml] [--format="..."] [--raw] [command_name] Displays help for a command The <info>help</info> command displays help for a given command: @@ -23,15 +23,15 @@ + - - list [--format="..."] [--raw] [--xml] [namespace] + list [--xml] [--raw] [--format="..."] [namespace] Lists commands The <info>list</info> command lists all commands: @@ -82,15 +82,15 @@ - diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.json b/src/Symfony/Component/Console/Tests/Fixtures/application_2.json index 8c17081ea9f58..c45e58943fea7 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_2.json +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.json @@ -1 +1 @@ -{"commands":[{"name":"help","usage":"help [--format=\"...\"] [--raw] [--xml] [command_name]","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the --format<\/comment> option:\n\n php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats.","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command help.","default":false},"xml":{"name":"--xml","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output help as XML.","default":false},"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message.","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message.","default":false},"verbose":{"name":"--verbose","shortcut":"-v","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase verbosity of messages.","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version.","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output.","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output.","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question.","default":false}}}},{"name":"list","usage":"list [--format=\"...\"] [--raw] [--xml] [namespace]","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the --format<\/comment> option:\n\n php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php app\/console list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output list in other formats.","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list.","default":false},"xml":{"name":"--xml","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output list as XML.","default":false}}}},{"name":"descriptor:command1","usage":"descriptor:command1","description":"command 1 description","help":"command 1 help","aliases":["alias1","alias2"],"definition":{"arguments":[],"options":{"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message.","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message.","default":false},"verbose":{"name":"--verbose","shortcut":"-v","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase verbosity of messages.","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version.","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output.","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output.","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question.","default":false}}}},{"name":"descriptor:command2","usage":"descriptor:command2 [-o|--option_name] argument_name","description":"command 2 description","help":"command 2 help","aliases":[],"definition":{"arguments":{"argument_name":{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null}},"options":{"option_name":{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false},"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message.","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message.","default":false},"verbose":{"name":"--verbose","shortcut":"-v","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase verbosity of messages.","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version.","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output.","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output.","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question.","default":false}}}}],"namespaces":[{"id":"_global","commands":["alias1","alias2","help","list"]},{"id":"descriptor","commands":["descriptor:command1","descriptor:command2"]}]} \ No newline at end of file +{"commands":[{"name":"help","usage":"help [--xml] [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the --format<\/comment> option:\n\n php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"xml":{"name":"--xml","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output help as XML","default":false},"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command help","default":false},"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message.","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message.","default":false},"verbose":{"name":"--verbose","shortcut":"-v","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase verbosity of messages.","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version.","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output.","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output.","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question.","default":false}}}},{"name":"list","usage":"list [--xml] [--raw] [--format=\"...\"] [namespace]","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the --format<\/comment> option:\n\n php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php app\/console list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"xml":{"name":"--xml","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output list as XML","default":false},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false},"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output list in other formats","default":null}}}},{"name":"descriptor:command1","usage":"descriptor:command1","description":"command 1 description","help":"command 1 help","aliases":["alias1","alias2"],"definition":{"arguments":[],"options":{"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message.","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message.","default":false},"verbose":{"name":"--verbose","shortcut":"-v","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase verbosity of messages.","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version.","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output.","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output.","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question.","default":false}}}},{"name":"descriptor:command2","usage":"descriptor:command2 [-o|--option_name] argument_name","description":"command 2 description","help":"command 2 help","aliases":[],"definition":{"arguments":{"argument_name":{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null}},"options":{"option_name":{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false},"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message.","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message.","default":false},"verbose":{"name":"--verbose","shortcut":"-v","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase verbosity of messages.","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version.","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output.","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output.","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question.","default":false}}}}],"namespaces":[{"id":"_global","commands":["alias1","alias2","help","list"]},{"id":"descriptor","commands":["descriptor:command1","descriptor:command2"]}]} \ No newline at end of file diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.md b/src/Symfony/Component/Console/Tests/Fixtures/application_2.md index 0dde6d3a65e61..f8225ae2531e4 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_2.md +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.md @@ -15,7 +15,7 @@ help ---- * Description: Displays help for a command -* Usage: `help [--format="..."] [--raw] [--xml] [command_name]` +* Usage: `help [--xml] [--format="..."] [--raw] [command_name]` * Aliases: The help command displays help for a given command: @@ -40,6 +40,16 @@ To display the list of available commands, please use the list comm ### Options: +**xml:** + +* Name: `--xml` +* Shortcut: +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: To output help as XML +* Default: `false` + **format:** * Name: `--format` @@ -47,7 +57,7 @@ To display the list of available commands, please use the list comm * Accept value: yes * Is value required: yes * Is multiple: no -* Description: To output help in other formats. +* Description: To output help in other formats * Default: `NULL` **raw:** @@ -57,17 +67,7 @@ To display the list of available commands, please use the list comm * Accept value: no * Is value required: no * Is multiple: no -* Description: To output raw command help. -* Default: `false` - -**xml:** - -* Name: `--xml` -* Shortcut: -* Accept value: no -* Is value required: no -* Is multiple: no -* Description: To output help as XML. +* Description: To output raw command help * Default: `false` **help:** @@ -144,7 +144,7 @@ list ---- * Description: Lists commands -* Usage: `list [--format="..."] [--raw] [--xml] [namespace]` +* Usage: `list [--xml] [--raw] [--format="..."] [namespace]` * Aliases: The list command lists all commands: @@ -175,15 +175,15 @@ It's also possible to get raw list of commands (useful for embedding command run ### Options: -**format:** +**xml:** -* Name: `--format` +* Name: `--xml` * Shortcut: -* Accept value: yes -* Is value required: yes +* Accept value: no +* Is value required: no * Is multiple: no -* Description: To output list in other formats. -* Default: `NULL` +* Description: To output list as XML +* Default: `false` **raw:** @@ -192,18 +192,18 @@ It's also possible to get raw list of commands (useful for embedding command run * Accept value: no * Is value required: no * Is multiple: no -* Description: To output raw command list. +* Description: To output raw command list * Default: `false` -**xml:** +**format:** -* Name: `--xml` +* Name: `--format` * Shortcut: -* Accept value: no -* Is value required: no +* Accept value: yes +* Is value required: yes * Is multiple: no -* Description: To output list as XML. -* Default: `false` +* Description: To output list in other formats +* Default: `NULL` descriptor:command1 ------------------- diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.xml b/src/Symfony/Component/Console/Tests/Fixtures/application_2.xml index fbc78cca5c362..b48546849209e 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_2.xml +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.xml @@ -2,7 +2,7 @@ - help [--format="..."] [--raw] [--xml] [command_name] + help [--xml] [--format="..."] [--raw] [command_name] Displays help for a command The <info>help</info> command displays help for a given command: @@ -23,15 +23,15 @@ + - - list [--format="..."] [--raw] [--xml] [namespace] + list [--xml] [--raw] [--format="..."] [namespace] Lists commands The <info>list</info> command lists all commands: @@ -82,15 +82,15 @@ - diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_asxml1.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_asxml1.txt index 136ba7ed31be3..965bc704f2372 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_asxml1.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_asxml1.txt @@ -2,7 +2,7 @@ - help [--format="..."] [--raw] [--xml] [command_name] + help [--xml] [--format="..."] [--raw] [command_name] Displays help for a command The <info>help</info> command displays help for a given command: @@ -23,15 +23,15 @@ + - - list [--format="..."] [--raw] [--xml] [namespace] + list [--xml] [--raw] [--format="..."] [namespace] Lists commands The <info>list</info> command lists all commands: @@ -82,15 +82,15 @@ - diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt index 5cc75b7413ddd..c758129bee967 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt @@ -6,6 +6,6 @@ -list [--format="..."] [--raw] [--xml] [namespace] +list [--xml] [--raw] [--format="..."] [namespace] diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_run2.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_run2.txt index 4fee44aefcf1a..627d9ba69b486 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_run2.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_run2.txt @@ -1,14 +1,14 @@ Usage: - help [--format="..."] [--raw] [--xml] [command_name] + help [--xml] [--format="..."] [--raw] [command_name] Arguments: command The command to execute command_name The command name (default: "help") Options: - --format To output help in other formats. - --raw To output raw command help. - --xml To output help as XML. + --xml To output help as XML + --format To output help in other formats + --raw To output raw command help --help (-h) Display this help message. --quiet (-q) Do not output any message. --verbose (-v) Increase verbosity of messages. diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_run3.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_run3.txt index d478348026e79..68bf516ded16a 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_run3.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_run3.txt @@ -1,13 +1,13 @@ Usage: - list [--format="..."] [--raw] [--xml] [namespace] + list [--xml] [--raw] [--format="..."] [namespace] Arguments: namespace The namespace name Options: - --format To output list in other formats. - --raw To output raw command list. - --xml To output list as XML. + --xml To output list as XML + --raw To output raw command list + --format To output list in other formats Help: The list command lists all commands: