Browse files

[Console] made descriptors use output instead of returning a string

[console] made descriptors use output instead of returning a string
[console] updated descriptors usage
[console] fixed descriptors usage & tests
[console] applied advices from github
[Console] applied advices from github

updated changelog
  • Loading branch information...
1 parent 470446b commit ec9c10334496b2e3e4a18935c2b1682f515eabb3 @jfsimon jfsimon committed Jul 8, 2013
View
14 Application.php
@@ -20,6 +20,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputAwareInterface;
+use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
@@ -685,8 +686,10 @@ public static function getAbbreviations($names)
public function asText($namespace = null, $raw = false)
{
$descriptor = new TextDescriptor();
+ $output = new BufferedOutput(BufferedOutput::VERBOSITY_NORMAL, !$raw);
+ $descriptor->describe($output, $this, array('namespace' => $namespace, 'raw_output' => true));
- return $descriptor->describe($this, array('namespace' => $namespace, 'raw_text' => $raw));
+ return $output->fetch();
}
/**
@@ -703,7 +706,14 @@ public function asXml($namespace = null, $asDom = false)
{
$descriptor = new XmlDescriptor();
- return $descriptor->describe($this, array('namespace' => $namespace, 'as_dom' => $asDom));
+ if ($asDom) {
+ return $descriptor->getApplicationDocument($this, $namespace);
+ }
+
+ $output = new BufferedOutput();
+ $descriptor->describe($output, $this, array('namespace' => $namespace));
+
+ return $output->fetch();
}
/**
View
5 CHANGELOG.md
@@ -1,6 +1,11 @@
CHANGELOG
=========
+2.4.0
+-----
+
+ * [BC BREAK] made descriptors use output instead of returning a string
+
2.3.0
-----
View
18 Command/Command.php
@@ -17,6 +17,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\HelperSet;
@@ -576,8 +577,10 @@ public function getHelper($name)
public function asText()
{
$descriptor = new TextDescriptor();
-
- return $descriptor->describe($this);
+ $output = new BufferedOutput(BufferedOutput::VERBOSITY_NORMAL, true);
+ $descriptor->describe($output, $this, array('raw_output' => true));
+
+ return $output->fetch();
}
/**
@@ -592,8 +595,15 @@ public function asText()
public function asXml($asDom = false)
{
$descriptor = new XmlDescriptor();
-
- return $descriptor->describe($this, array('as_dom' => $asDom));
+
+ if ($asDom) {
+ return $descriptor->getCommandDocument($this);
+ }
+
+ $output = new BufferedOutput();
+ $descriptor->describe($output, $this);
+
+ return $output->fetch();
}
private function validateName($name)
View
8 Command/HelpCommand.php
@@ -38,7 +38,7 @@ protected function configure()
->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('format', null, InputOption::VALUE_REQUIRED, 'To output help in other formats', 'txt'),
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command help'),
))
->setDescription('Displays help for a command')
@@ -81,7 +81,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
$helper = new DescriptorHelper();
- $helper->describe($output, $this->command, $input->getOption('format'), $input->getOption('raw'));
+ $helper->describe($output, $this->command, array(
+ 'format' => $input->getOption('format'),
+ 'raw' => $input->getOption('raw'),
+ ));
+
$this->command = null;
}
}
View
8 Command/ListCommand.php
@@ -73,7 +73,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
$helper = new DescriptorHelper();
- $helper->describe($output, $this->getApplication(), $input->getOption('format'), $input->getOption('raw'), $input->getArgument('namespace'));
+ $helper->describe($output, $this->getApplication(), array(
+ 'format' => $input->getOption('format'),
+ 'raw_text' => $input->getOption('raw'),
+ 'namespace' => $input->getArgument('namespace'),
+ ));
}
/**
@@ -85,7 +89,7 @@ private function createDefinition()
new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
new InputOption('xml', null, InputOption::VALUE_NONE, 'To output list as XML'),
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'),
- new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output list in other formats'),
+ new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output list in other formats', 'txt'),
));
}
}
View
41 Descriptor/Descriptor.php
@@ -16,28 +16,55 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
/**
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
*/
abstract class Descriptor implements DescriptorInterface
{
- public function describe($object, array $options = array())
+ /**
+ * @var OutputInterface
+ */
+ private $output;
+
+ /**
+ * {@inheritdoc}
+ */
+ public function describe(OutputInterface $output, $object, array $options = array())
{
+ $this->output = $output;
+
switch (true) {
case $object instanceof InputArgument:
- return $this->describeInputArgument($object, $options);
+ $this->describeInputArgument($object, $options);
+ break;
case $object instanceof InputOption:
- return $this->describeInputOption($object, $options);
+ $this->describeInputOption($object, $options);
+ break;
case $object instanceof InputDefinition:
- return $this->describeInputDefinition($object, $options);
+ $this->describeInputDefinition($object, $options);
+ break;
case $object instanceof Command:
- return $this->describeCommand($object, $options);
+ $this->describeCommand($object, $options);
+ break;
case $object instanceof Application:
- return $this->describeApplication($object, $options);
+ $this->describeApplication($object, $options);
+ break;
+ default:
+ throw new \InvalidArgumentException(sprintf('Object of type "%s" is not describable.', get_class($object)));
}
+ }
- throw new \InvalidArgumentException(sprintf('Object of type "%s" is not describable.', get_class($object)));
+ /**
+ * Writes content to output.
+ *
+ * @param string $content
+ * @param boolean $decorated
+ */
+ protected function write($content, $decorated = false)
+ {
+ $this->output->write($content, false, $decorated ? OutputInterface::OUTPUT_NORMAL : OutputInterface::OUTPUT_RAW);
}
/**
View
11 Descriptor/DescriptorInterface.php
@@ -11,6 +11,8 @@
namespace Symfony\Component\Console\Descriptor;
+use Symfony\Component\Console\Output\OutputInterface;
+
/**
* Descriptor interface.
*
@@ -21,10 +23,9 @@
/**
* Describes an InputArgument instance.
*
- * @param object $object
- * @param array $options
- *
- * @return string|mixed
+ * @param OutputInterface $output
+ * @param object $object
+ * @param array $options
*/
- public function describe($object, array $options = array());
+ public function describe(OutputInterface $output, $object, array $options = array());
}
View
126 Descriptor/JsonDescriptor.php
@@ -29,65 +29,31 @@ class JsonDescriptor extends Descriptor
*/
protected function describeInputArgument(InputArgument $argument, array $options = array())
{
- return $this->output(array(
- 'name' => $argument->getName(),
- 'is_required' => $argument->isRequired(),
- 'is_array' => $argument->isArray(),
- 'description' => $argument->getDescription(),
- 'default' => $argument->getDefault(),
- ), $options);
+ $this->writeData($this->getInputArgumentData($argument), $options);
}
/**
* {@inheritdoc}
*/
protected function describeInputOption(InputOption $option, array $options = array())
{
- return $this->output(array(
- 'name' => '--'.$option->getName(),
- 'shortcut' => $option->getShortcut() ? '-'.implode('|-', explode('|', $option->getShortcut())) : '',
- 'accept_value' => $option->acceptValue(),
- 'is_value_required' => $option->isValueRequired(),
- 'is_multiple' => $option->isArray(),
- 'description' => $option->getDescription(),
- 'default' => $option->getDefault(),
- ), $options);
+ $this->writeData($this->getInputOptionData($option), $options);
}
/**
* {@inheritdoc}
*/
protected function describeInputDefinition(InputDefinition $definition, array $options = array())
{
- $inputArguments = array();
- foreach ($definition->getArguments() as $name => $argument) {
- $inputArguments[$name] = $this->describeInputArgument($argument, array('as_array' => true));
- }
-
- $inputOptions = array();
- foreach ($definition->getOptions() as $name => $option) {
- $inputOptions[$name] = $this->describeInputOption($option, array('as_array' => true));
- }
-
- return $this->output(array('arguments' => $inputArguments, 'options' => $inputOptions), $options);
+ $this->writeData($this->getInputDefinitionData($definition), $options);
}
/**
* {@inheritdoc}
*/
protected function describeCommand(Command $command, array $options = array())
{
- $command->getSynopsis();
- $command->mergeApplicationDefinition(false);
-
- return $this->output(array(
- 'name' => $command->getName(),
- 'usage' => $command->getSynopsis(),
- 'description' => $command->getDescription(),
- 'help' => $command->getProcessedHelp(),
- 'aliases' => $command->getAliases(),
- 'definition' => $this->describeInputDefinition($command->getNativeDefinition(), array('as_array' => true)),
- ), $options);
+ $this->writeData($this->getCommandData($command), $options);
}
/**
@@ -100,30 +66,100 @@ protected function describeApplication(Application $application, array $options
$commands = array();
foreach ($description->getCommands() as $command) {
- $commands[] = $this->describeCommand($command, array('as_array' => true));
+ $commands[] = $this->getCommandData($command);
}
$data = $describedNamespace
? array('commands' => $commands, 'namespace' => $describedNamespace)
: array('commands' => $commands, 'namespaces' => array_values($description->getNamespaces()));
- return $this->output($data, $options);
+ $this->writeData($data, $options);
}
/**
- * Outputs data as array or string according to options.
+ * Writes data as json.
*
* @param array $data
* @param array $options
*
* @return array|string
*/
- private function output(array $data, array $options)
+ private function writeData(array $data, array $options)
+ {
+ $this->write(json_encode($data, isset($options['json_encoding']) ? $options['json_encoding'] : 0));
+ }
+
+ /**
+ * @param InputArgument $argument
+ *
+ * @return array
+ */
+ private function getInputArgumentData(InputArgument $argument)
+ {
+ return array(
+ 'name' => $argument->getName(),
+ 'is_required' => $argument->isRequired(),
+ 'is_array' => $argument->isArray(),
+ 'description' => $argument->getDescription(),
+ 'default' => $argument->getDefault(),
+ );
+ }
+
+ /**
+ * @param InputOption $option
+ *
+ * @return array
+ */
+ private function getInputOptionData(InputOption $option)
+ {
+ return array(
+ 'name' => '--'.$option->getName(),
+ 'shortcut' => $option->getShortcut() ? '-'.implode('|-', explode('|', $option->getShortcut())) : '',
+ 'accept_value' => $option->acceptValue(),
+ 'is_value_required' => $option->isValueRequired(),
+ 'is_multiple' => $option->isArray(),
+ 'description' => $option->getDescription(),
+ 'default' => $option->getDefault(),
+ );
+ }
+
+ /**
+ * @param InputDefinition $definition
+ *
+ * @return array
+ */
+ private function getInputDefinitionData(InputDefinition $definition)
{
- if (isset($options['as_array']) && $options['as_array']) {
- return $data;
+ $inputArguments = array();
+ foreach ($definition->getArguments() as $name => $argument) {
+ $inputArguments[$name] = $this->getInputArgumentData($argument);
+ }
+
+ $inputOptions = array();
+ foreach ($definition->getOptions() as $name => $option) {
+ $inputOptions[$name] = $this->getInputOptionData($option);
}
- return json_encode($data, isset($options['json_encoding']) ? $options['json_encoding'] : 0);
+ return array('arguments' => $inputArguments, 'options' => $inputOptions);
+ }
+
+ /**
+ * @param Command $command
+ *
+ * @return array
+ */
+ private function getCommandData(Command $command)
+ {
+ $command->getSynopsis();
+ $command->mergeApplicationDefinition(false);
+
+ return array(
+ 'name' => $command->getName(),
+ 'usage' => $command->getSynopsis(),
+ 'description' => $command->getDescription(),
+ 'help' => $command->getProcessedHelp(),
+ 'aliases' => $command->getAliases(),
+ 'definition' => $this->getInputDefinitionData($command->getNativeDefinition()),
+ );
}
}
View
62 Descriptor/MarkdownDescriptor.php
@@ -29,51 +29,57 @@ class MarkdownDescriptor extends Descriptor
*/
protected function describeInputArgument(InputArgument $argument, array $options = array())
{
- return '**'.$argument->getName().':**'."\n\n"
+ $this->write(
+ '**'.$argument->getName().':**'."\n\n"
.'* Name: '.($argument->getName() ?: '<none>')."\n"
.'* Is required: '.($argument->isRequired() ? 'yes' : 'no')."\n"
.'* Is array: '.($argument->isArray() ? 'yes' : 'no')."\n"
.'* Description: '.($argument->getDescription() ?: '<none>')."\n"
- .'* Default: `'.str_replace("\n", '', var_export($argument->getDefault(), true)).'`';
+ .'* Default: `'.str_replace("\n", '', var_export($argument->getDefault(), true)).'`'
+ );
}
/**
* {@inheritdoc}
*/
protected function describeInputOption(InputOption $option, array $options = array())
{
- return '**'.$option->getName().':**'."\n\n"
+ $this->write(
+ '**'.$option->getName().':**'."\n\n"
.'* Name: `--'.$option->getName().'`'."\n"
.'* Shortcut: '.($option->getShortcut() ? '`-'.implode('|-', explode('|', $option->getShortcut())).'`' : '<none>')."\n"
.'* Accept value: '.($option->acceptValue() ? 'yes' : 'no')."\n"
.'* Is value required: '.($option->isValueRequired() ? 'yes' : 'no')."\n"
.'* Is multiple: '.($option->isArray() ? 'yes' : 'no')."\n"
.'* Description: '.($option->getDescription() ?: '<none>')."\n"
- .'* Default: `'.str_replace("\n", '', var_export($option->getDefault(), true)).'`';
+ .'* Default: `'.str_replace("\n", '', var_export($option->getDefault(), true)).'`'
+ );
}
/**
* {@inheritdoc}
*/
protected function describeInputDefinition(InputDefinition $definition, array $options = array())
{
- $blocks = array();
-
- if (count($definition->getArguments()) > 0) {
- $blocks[] = '### Arguments:';
+ if ($showArguments = count($definition->getArguments()) > 0) {
+ $this->write('### Arguments:');
foreach ($definition->getArguments() as $argument) {
- $blocks[] = $this->describeInputArgument($argument);
+ $this->write("\n\n");
+ $this->write($this->describeInputArgument($argument));
}
}
if (count($definition->getOptions()) > 0) {
- $blocks[] = '### Options:';
+ if ($showArguments) {
+ $this->write("\n\n");
+ }
+
+ $this->write('### Options:');
foreach ($definition->getOptions() as $option) {
- $blocks[] = $this->describeInputOption($option);
+ $this->write("\n\n");
+ $this->write($this->describeInputOption($option));
}
}
-
- return implode("\n\n", $blocks);
}
/**
@@ -84,21 +90,23 @@ protected function describeCommand(Command $command, array $options = array())
$command->getSynopsis();
$command->mergeApplicationDefinition(false);
- $markdown = $command->getName()."\n"
+ $this->write(
+ $command->getName()."\n"
.str_repeat('-', strlen($command->getName()))."\n\n"
.'* Description: '.($command->getDescription() ?: '<none>')."\n"
.'* Usage: `'.$command->getSynopsis().'`'."\n"
- .'* Aliases: '.(count($command->getAliases()) ? '`'.implode('`, `', $command->getAliases()).'`' : '<none>');
+ .'* Aliases: '.(count($command->getAliases()) ? '`'.implode('`, `', $command->getAliases()).'`' : '<none>')
+ );
if ($help = $command->getProcessedHelp()) {
- $markdown .= "\n\n".$help;
+ $this->write("\n\n");
+ $this->write($help);
}
- if ($definitionMarkdown = $this->describeInputDefinition($command->getNativeDefinition())) {
- $markdown .= "\n\n".$definitionMarkdown;
+ if ($definition = $command->getNativeDefinition()) {
+ $this->write("\n\n");
+ $this->describeInputDefinition($command->getNativeDefinition());
}
-
- return $markdown;
}
/**
@@ -108,22 +116,24 @@ protected function describeApplication(Application $application, array $options
{
$describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
$description = new ApplicationDescription($application, $describedNamespace);
- $blocks = array($application->getName()."\n".str_repeat('=', strlen($application->getName())));
+
+ $this->write($application->getName()."\n".str_repeat('=', strlen($application->getName())));
foreach ($description->getNamespaces() as $namespace) {
if (ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
- $blocks[] = '**'.$namespace['id'].':**';
+ $this->write("\n\n");
+ $this->write('**'.$namespace['id'].':**');
}
- $blocks[] = implode("\n", array_map(function ($commandName) {
+ $this->write("\n\n");
+ $this->write(array_map(function ($commandName) {
return '* '.$commandName;
} , $namespace['commands']));
}
foreach ($description->getCommands() as $command) {
- $blocks[] = $this->describeCommand($command);
+ $this->write("\n\n");
+ $this->write($this->describeCommand($command));
}
-
- return implode("\n\n", $blocks);
}
}
View
100 Descriptor/TextDescriptor.php
@@ -16,6 +16,7 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
/**
* Text descriptor.
@@ -36,10 +37,12 @@ protected function describeInputArgument(InputArgument $argument, array $options
}
$nameWidth = isset($options['name_width']) ? $options['name_width'] : strlen($argument->getName());
- $output = str_replace("\n", "\n".str_repeat(' ', $nameWidth + 2), $argument->getDescription());
- $output = sprintf(" <info>%-${nameWidth}s</info> %s%s", $argument->getName(), $output, $default);
- return isset($options['raw_text']) && $options['raw_text'] ? strip_tags($output) : $output;
+ $this->writeText(sprintf(" <info>%-${nameWidth}s</info> %s%s",
+ $argument->getName(),
+ str_replace("\n", "\n".str_repeat(' ', $nameWidth + 2), $argument->getDescription()),
+ $default
+ ), $options);
}
/**
@@ -56,15 +59,13 @@ protected function describeInputOption(InputOption $option, array $options = arr
$nameWidth = isset($options['name_width']) ? $options['name_width'] : strlen($option->getName());
$nameWithShortcutWidth = $nameWidth - strlen($option->getName()) - 2;
- $output = sprintf(" <info>%s</info> %-${nameWithShortcutWidth}s%s%s%s",
+ $this->writeText(sprintf(" <info>%s</info> %-${nameWithShortcutWidth}s%s%s%s",
'--'.$option->getName(),
$option->getShortcut() ? sprintf('(-%s) ', $option->getShortcut()) : '',
str_replace("\n", "\n".str_repeat(' ', $nameWidth + 2), $option->getDescription()),
$default,
$option->isArray() ? '<comment> (multiple values allowed)</comment>' : ''
- );
-
- return isset($options['raw_text']) && $options['raw_text'] ? strip_tags($output) : $output;
+ ), $options);
}
/**
@@ -85,27 +86,27 @@ protected function describeInputDefinition(InputDefinition $definition, array $o
}
++$nameWidth;
- $messages = array();
-
if ($definition->getArguments()) {
- $messages[] = '<comment>Arguments:</comment>';
+ $this->writeText('<comment>Arguments:</comment>', $options);
+ $this->writeText("\n");
foreach ($definition->getArguments() as $argument) {
- $messages[] = $this->describeInputArgument($argument, array('name_width' => $nameWidth));
+ $this->describeInputArgument($argument, array_merge($options, array('name_width' => $nameWidth)));
+ $this->writeText("\n");
}
- $messages[] = '';
+ }
+
+ if ($definition->getArguments() && $definition->getOptions()) {
+ $this->writeText("\n");
}
if ($definition->getOptions()) {
- $messages[] = '<comment>Options:</comment>';
+ $this->writeText('<comment>Options:</comment>', $options);
+ $this->writeText("\n");
foreach ($definition->getOptions() as $option) {
- $messages[] = $this->describeInputOption($option, array('name_width' => $nameWidth));
+ $this->describeInputOption($option, array_merge($options, array('name_width' => $nameWidth)));
+ $this->writeText("\n");
}
- $messages[] = '';
}
-
- $output = implode("\n", $messages);
-
- return isset($options['raw_text']) && $options['raw_text'] ? strip_tags($output) : $output;
}
/**
@@ -115,22 +116,30 @@ protected function describeCommand(Command $command, array $options = array())
{
$command->getSynopsis();
$command->mergeApplicationDefinition(false);
- $messages = array('<comment>Usage:</comment>', ' '.$command->getSynopsis(), '');
- if ($command->getAliases()) {
- $messages[] = '<comment>Aliases:</comment> <info>'.implode(', ', $command->getAliases()).'</info>';
+ $this->writeText('<comment>Usage:</comment>', $options);
+ $this->writeText("\n");
+ $this->writeText(' '.$command->getSynopsis(), $options);
+ $this->writeText("\n");
+
+ if (count($command->getAliases()) > 0) {
+ $this->writeText("\n");
+ $this->writeText('<comment>Aliases:</comment> <info>'.implode(', ', $command->getAliases()).'</info>', $options);
}
- $messages[] = $this->describeInputDefinition($command->getNativeDefinition());
+ if ($definition = $command->getNativeDefinition()) {
+ $this->writeText("\n");
+ $this->describeInputDefinition($definition, $options);
+ }
+
+ $this->writeText("\n");
if ($help = $command->getProcessedHelp()) {
- $messages[] = '<comment>Help:</comment>';
- $messages[] = ' '.str_replace("\n", "\n ", $help)."\n";
+ $this->writeText('<comment>Help:</comment>', $options);
+ $this->writeText("\n");
+ $this->writeText(' '.str_replace("\n", "\n ", $help), $options);
+ $this->writeText("\n");
}
-
- $output = implode("\n", $messages);
-
- return isset($options['raw_text']) && $options['raw_text'] ? strip_tags($output) : $output;
}
/**
@@ -140,41 +149,52 @@ protected function describeApplication(Application $application, array $options
{
$describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
$description = new ApplicationDescription($application, $describedNamespace);
- $messages = array();
if (isset($options['raw_text']) && $options['raw_text']) {
$width = $this->getColumnWidth($description->getCommands());
foreach ($description->getCommands() as $command) {
- $messages[] = sprintf("%-${width}s %s", $command->getName(), $command->getDescription());
+ $this->writeText(sprintf("%-${width}s %s", $command->getName(), $command->getDescription()), $options);
+ $this->writeText("\n");
}
} else {
$width = $this->getColumnWidth($description->getCommands());
- $messages[] = $application->getHelp();
- $messages[] = '';
+ $this->writeText($application->getHelp(), $options);
+ $this->writeText("\n\n");
if ($describedNamespace) {
- $messages[] = sprintf("<comment>Available commands for the \"%s\" namespace:</comment>", $describedNamespace);
+ $this->writeText(sprintf("<comment>Available commands for the \"%s\" namespace:</comment>", $describedNamespace), $options);
} else {
- $messages[] = '<comment>Available commands:</comment>';
+ $this->writeText('<comment>Available commands:</comment>', $options);
}
// add commands by namespace
foreach ($description->getNamespaces() as $namespace) {
if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
- $messages[] = '<comment>'.$namespace['id'].'</comment>';
+ $this->writeText("\n");
+ $this->writeText('<comment>'.$namespace['id'].'</comment>', $options);
}
foreach ($namespace['commands'] as $name) {
- $messages[] = sprintf(" <info>%-${width}s</info> %s", $name, $description->getCommand($name)->getDescription());
+ $this->writeText("\n");
+ $this->writeText(sprintf(" <info>%-${width}s</info> %s", $name, $description->getCommand($name)->getDescription()), $options);
}
}
+
+ $this->writeText("\n");
}
+ }
- $output = implode("\n", $messages);
-
- return isset($options['raw_text']) && $options['raw_text'] ? strip_tags($output) : $output;
+ /**
+ * {@inheritdoc}
+ */
+ private function writeText($content, array $options = array())
+ {
+ $this->write(
+ isset($options['raw_text']) && $options['raw_text'] ? strip_tags($content) : $content,
+ isset($options['raw_output']) ? !$options['raw_output'] : true
+ );
}
/**
View
226 Descriptor/XmlDescriptor.php
@@ -25,91 +25,34 @@
class XmlDescriptor extends Descriptor
{
/**
- * {@inheritdoc}
- */
- protected function describeInputArgument(InputArgument $argument, array $options = array())
- {
- $dom = new \DOMDocument('1.0', 'UTF-8');
-
- $dom->appendChild($objectXML = $dom->createElement('argument'));
- $objectXML->setAttribute('name', $argument->getName());
- $objectXML->setAttribute('is_required', $argument->isRequired() ? 1 : 0);
- $objectXML->setAttribute('is_array', $argument->isArray() ? 1 : 0);
- $objectXML->appendChild($descriptionXML = $dom->createElement('description'));
- $descriptionXML->appendChild($dom->createTextNode($argument->getDescription()));
-
- $objectXML->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));
- }
-
- return $this->output($dom, $options);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function describeInputOption(InputOption $option, array $options = array())
- {
- $dom = new \DOMDocument('1.0', 'UTF-8');
-
- $dom->appendChild($objectXML = $dom->createElement('option'));
- $objectXML->setAttribute('name', '--'.$option->getName());
- $pos = strpos($option->getShortcut(), '|');
- if (false !== $pos) {
- $objectXML->setAttribute('shortcut', '-'.substr($option->getShortcut(), 0, $pos));
- $objectXML->setAttribute('shortcuts', '-'.implode('|-', explode('|', $option->getShortcut())));
- } else {
- $objectXML->setAttribute('shortcut', $option->getShortcut() ? '-'.$option->getShortcut() : '');
- }
- $objectXML->setAttribute('accept_value', $option->acceptValue() ? 1 : 0);
- $objectXML->setAttribute('is_value_required', $option->isValueRequired() ? 1 : 0);
- $objectXML->setAttribute('is_multiple', $option->isArray() ? 1 : 0);
- $objectXML->appendChild($descriptionXML = $dom->createElement('description'));
- $descriptionXML->appendChild($dom->createTextNode($option->getDescription()));
-
- if ($option->acceptValue()) {
- $defaults = is_array($option->getDefault()) ? $option->getDefault() : (is_bool($option->getDefault()) ? array(var_export($option->getDefault(), true)) : ($option->getDefault() ? array($option->getDefault()) : array()));
- $objectXML->appendChild($defaultsXML = $dom->createElement('defaults'));
-
- if (!empty($defaults)) {
- foreach ($defaults as $default) {
- $defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
- $defaultXML->appendChild($dom->createTextNode($default));
- }
- }
- }
-
- return $this->output($dom, $options);
- }
-
- /**
- * {@inheritdoc}
+ * @param InputDefinition $definition
+ *
+ * @return \DOMDocument
*/
- protected function describeInputDefinition(InputDefinition $definition, array $options = array())
+ public function getInputDefinitionDocument(InputDefinition $definition)
{
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->appendChild($definitionXML = $dom->createElement('definition'));
$definitionXML->appendChild($argumentsXML = $dom->createElement('arguments'));
foreach ($definition->getArguments() as $argument) {
- $this->appendDocument($argumentsXML, $this->describeInputArgument($argument, array('as_dom' => true)));
+ $this->appendDocument($argumentsXML, $this->getInputArgumentDocument($argument));
}
$definitionXML->appendChild($optionsXML = $dom->createElement('options'));
foreach ($definition->getOptions() as $option) {
- $this->appendDocument($optionsXML, $this->describeInputOption($option, array('as_dom' => true)));
+ $this->appendDocument($optionsXML, $this->getInputOptionDocument($option));
}
- return $this->output($dom, $options);
+ return $dom;
}
-
+
/**
- * {@inheritdoc}
+ * @param Command $command
+ *
+ * @return \DOMDocument
*/
- protected function describeCommand(Command $command, array $options = array())
+ public function getCommandDocument(Command $command)
{
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->appendChild($commandXML = $dom->createElement('command'));
@@ -135,47 +78,89 @@ protected function describeCommand(Command $command, array $options = array())
$aliasXML->appendChild($dom->createTextNode($alias));
}
- $definitionXML = $this->describeInputDefinition($command->getNativeDefinition(), array('as_dom' => true));
+ $definitionXML = $this->getInputDefinitionDocument($command->getNativeDefinition());
$this->appendDocument($commandXML, $definitionXML->getElementsByTagName('definition')->item(0));
- return $this->output($dom, $options);
+ return $dom;
}
-
+
/**
- * {@inheritdoc}
+ * @param Application $application
+ * @param string|null $namespace
+ *
+ * @return \DOMDocument
*/
- protected function describeApplication(Application $application, array $options = array())
+ public function getApplicationDocument(Application $application, $namespace = null)
{
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->appendChild($rootXml = $dom->createElement('symfony'));
$rootXml->appendChild($commandsXML = $dom->createElement('commands'));
- $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
- $description = new ApplicationDescription($application, $describedNamespace);
+ $description = new ApplicationDescription($application, $namespace);
- if ($describedNamespace) {
- $commandsXML->setAttribute('namespace', $describedNamespace);
+ if ($namespace) {
+ $commandsXML->setAttribute('namespace', $namespace);
}
foreach ($description->getCommands() as $command) {
- $this->appendDocument($commandsXML, $this->describeCommand($command, array('as_dom' => true)));
+ $this->appendDocument($commandsXML, $this->getCommandDocument($command));
}
- if (!$describedNamespace) {
+ if (!$namespace) {
$rootXml->appendChild($namespacesXML = $dom->createElement('namespaces'));
- foreach ($description->getNamespaces() as $namespace) {
+ foreach ($description->getNamespaces() as $namespaceDescription) {
$namespacesXML->appendChild($namespaceArrayXML = $dom->createElement('namespace'));
- $namespaceArrayXML->setAttribute('id', $namespace['id']);
+ $namespaceArrayXML->setAttribute('id', $namespaceDescription['id']);
- foreach ($namespace['commands'] as $name) {
+ foreach ($namespaceDescription['commands'] as $name) {
$namespaceArrayXML->appendChild($commandXML = $dom->createElement('command'));
$commandXML->appendChild($dom->createTextNode($name));
}
}
}
+
+ return $dom;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function describeInputArgument(InputArgument $argument, array $options = array())
+ {
+ $this->writeDocument($this->getInputArgumentDocument($argument));
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function describeInputOption(InputOption $option, array $options = array())
+ {
+ $this->writeDocument($this->getInputOptionDocument($option));
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function describeInputDefinition(InputDefinition $definition, array $options = array())
+ {
+ $this->writeDocument($this->getInputDefinitionDocument($definition));
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function describeCommand(Command $command, array $options = array())
+ {
+ $this->writeDocument($this->getCommandDocument($command));
+ }
- return $this->output($dom, $options);
+ /**
+ * {@inheritdoc}
+ */
+ protected function describeApplication(Application $application, array $options = array())
+ {
+ $this->writeDocument($this->getApplicationDocument($application, isset($options['namespace']) ? $options['namespace'] : null));
}
/**
@@ -192,21 +177,80 @@ private function appendDocument(\DOMNode $parentNode, \DOMNode $importedParent)
}
/**
- * Outputs document as DOMDocument or string according to options.
+ * Writes DOM document.
*
* @param \DOMDocument $dom
- * @param array $options
*
* @return \DOMDocument|string
*/
- private function output(\DOMDocument $dom, array $options)
+ private function writeDocument(\DOMDocument $dom)
+ {
+ $dom->formatOutput = true;
+ $this->write($dom->saveXML());
+ }
+
+ /**
+ * @param InputArgument $argument
+ *
+ * @return \DOMDocument
+ */
+ private function getInputArgumentDocument(InputArgument $argument)
{
- if (isset($options['as_dom']) && $options['as_dom']) {
- return $dom;
+ $dom = new \DOMDocument('1.0', 'UTF-8');
+
+ $dom->appendChild($objectXML = $dom->createElement('argument'));
+ $objectXML->setAttribute('name', $argument->getName());
+ $objectXML->setAttribute('is_required', $argument->isRequired() ? 1 : 0);
+ $objectXML->setAttribute('is_array', $argument->isArray() ? 1 : 0);
+ $objectXML->appendChild($descriptionXML = $dom->createElement('description'));
+ $descriptionXML->appendChild($dom->createTextNode($argument->getDescription()));
+
+ $objectXML->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));
}
- $dom->formatOutput = true;
+ return $dom;
+ }
+
+ /**
+ * @param InputOption $option
+ *
+ * @return \DOMDocument
+ */
+ private function getInputOptionDocument(InputOption $option)
+ {
+ $dom = new \DOMDocument('1.0', 'UTF-8');
+
+ $dom->appendChild($objectXML = $dom->createElement('option'));
+ $objectXML->setAttribute('name', '--'.$option->getName());
+ $pos = strpos($option->getShortcut(), '|');
+ if (false !== $pos) {
+ $objectXML->setAttribute('shortcut', '-'.substr($option->getShortcut(), 0, $pos));
+ $objectXML->setAttribute('shortcuts', '-'.implode('|-', explode('|', $option->getShortcut())));
+ } else {
+ $objectXML->setAttribute('shortcut', $option->getShortcut() ? '-'.$option->getShortcut() : '');
+ }
+ $objectXML->setAttribute('accept_value', $option->acceptValue() ? 1 : 0);
+ $objectXML->setAttribute('is_value_required', $option->isValueRequired() ? 1 : 0);
+ $objectXML->setAttribute('is_multiple', $option->isArray() ? 1 : 0);
+ $objectXML->appendChild($descriptionXML = $dom->createElement('description'));
+ $descriptionXML->appendChild($dom->createTextNode($option->getDescription()));
+
+ if ($option->acceptValue()) {
+ $defaults = is_array($option->getDefault()) ? $option->getDefault() : (is_bool($option->getDefault()) ? array(var_export($option->getDefault(), true)) : ($option->getDefault() ? array($option->getDefault()) : array()));
+ $objectXML->appendChild($defaultsXML = $dom->createElement('defaults'));
+
+ if (!empty($defaults)) {
+ foreach ($defaults as $default) {
+ $defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
+ $defaultXML->appendChild($dom->createTextNode($default));
+ }
+ }
+ }
- return $dom->saveXML();
+ return $dom;
}
}
View
20 Helper/DescriptorHelper.php
@@ -46,23 +46,29 @@ public function __construct()
/**
* Describes an object if supported.
*
+ * Available options are:
+ * * format: string, the output format name
+ * * raw_text: boolean, sets output type as raw
+ *
* @param OutputInterface $output
* @param object $object
- * @param string $format
- * @param boolean $raw
+ * @param array $options
+ *
+ * @throws \InvalidArgumentException
*/
- public function describe(OutputInterface $output, $object, $format = null, $raw = false, $namespace = null)
+ public function describe(OutputInterface $output, $object, array $options = array())
{
- $options = array('raw_text' => $raw, 'format' => $format ?: 'txt', 'namespace' => $namespace);
- $type = !$raw && 'txt' === $options['format'] ? OutputInterface::OUTPUT_NORMAL : OutputInterface::OUTPUT_RAW;
+ $options = array_merge(array(
+ 'raw_text' => false,
+ 'format' => 'txt',
+ ), $options);
if (!isset($this->descriptors[$options['format']])) {
throw new \InvalidArgumentException(sprintf('Unsupported format "%s".', $options['format']));
}
$descriptor = $this->descriptors[$options['format']];
-
- $output->writeln($descriptor->describe($object, $options), $type);
+ $descriptor->describe($output, $object, $options);
}
/**
View
18 Input/InputDefinition.php
@@ -13,6 +13,7 @@
use Symfony\Component\Console\Descriptor\TextDescriptor;
use Symfony\Component\Console\Descriptor\XmlDescriptor;
+use Symfony\Component\Console\Output\BufferedOutput;
/**
* A InputDefinition represents a set of valid command line arguments and options.
@@ -421,8 +422,10 @@ public function getSynopsis()
public function asText()
{
$descriptor = new TextDescriptor();
-
- return $descriptor->describe($this);
+ $output = new BufferedOutput(BufferedOutput::VERBOSITY_NORMAL, true);
+ $descriptor->describe($output, $this, array('raw_output' => true));
+
+ return $output->fetch();
}
/**
@@ -437,7 +440,14 @@ public function asText()
public function asXml($asDom = false)
{
$descriptor = new XmlDescriptor();
-
- return $descriptor->describe($this, array('as_dom' => $asDom));
+
+ if ($asDom) {
+ return $descriptor->getInputDefinitionDocument($this);
+ }
+
+ $output = new BufferedOutput();
+ $descriptor->describe($output, $this);
+
+ return $output->fetch();
}
}
View
49 Output/BufferedOutput.php
@@ -0,0 +1,49 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+
+namespace Symfony\Component\Console\Output;
+
+/**
+ * @author Jean-François Simon <contact@jfsimon.fr>
+ */
+class BufferedOutput extends Output
+{
+ /**
+ * @var string
+ */
+ private $buffer = '';
+
+ /**
+ * Empties buffer and returns its content.
+ *
+ * @return string
+ */
+ public function fetch()
+ {
+ $content = $this->buffer;
+ $this->buffer = '';
+
+ return $content;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function doWrite($message, $newline)
+ {
+ $this->buffer .= $message;
+
+ if ($newline) {
+ $this->buffer .= "\n";
+ }
+ }
+}
View
18 Tests/Descriptor/AbstractDescriptorTest.php
@@ -16,31 +16,32 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\BufferedOutput;
abstract class AbstractDescriptorTest extends \PHPUnit_Framework_TestCase
{
/** @dataProvider getDescribeInputArgumentTestData */
public function testDescribeInputArgument(InputArgument $argument, $expectedDescription)
{
- $this->assertEquals(trim($expectedDescription), trim($this->getDescriptor()->describe($argument)));
+ $this->assertDescription($expectedDescription, $argument);
}
/** @dataProvider getDescribeInputOptionTestData */
public function testDescribeInputOption(InputOption $option, $expectedDescription)
{
- $this->assertEquals(trim($expectedDescription), trim($this->getDescriptor()->describe($option)));
+ $this->assertDescription($expectedDescription, $option);
}
/** @dataProvider getDescribeInputDefinitionTestData */
public function testDescribeInputDefinition(InputDefinition $definition, $expectedDescription)
{
- $this->assertEquals(trim($expectedDescription), trim($this->getDescriptor()->describe($definition)));
+ $this->assertDescription($expectedDescription, $definition);
}
/** @dataProvider getDescribeCommandTestData */
public function testDescribeCommand(Command $command, $expectedDescription)
{
- $this->assertEquals(trim($expectedDescription), trim($this->getDescriptor()->describe($command)));
+ $this->assertDescription($expectedDescription, $command);
}
/** @dataProvider getDescribeApplicationTestData */
@@ -53,7 +54,7 @@ public function testDescribeApplication(Application $application, $expectedDescr
$command->setHelp(str_replace('%command.full_name%', 'app/console %command.name%', $command->getHelp()));
}
- $this->assertEquals(trim($expectedDescription), trim(str_replace(PHP_EOL, "\n", $this->getDescriptor()->describe($application))));
+ $this->assertDescription($expectedDescription, $application);
}
public function getDescribeInputArgumentTestData()
@@ -94,4 +95,11 @@ private function getDescriptionTestData(array $objects)
return $data;
}
+
+ private function assertDescription($expectedDescription, $describedObject)
+ {
+ $output = new BufferedOutput(BufferedOutput::VERBOSITY_NORMAL, true);
+ $this->getDescriptor()->describe($output, $describedObject, array('raw_output' => true));
+ $this->assertEquals(trim($expectedDescription), trim(str_replace(PHP_EOL, "\n", $output->fetch())));
+ }
}
View
2 Tests/Fixtures/application_1.json
@@ -1 +1 @@
-{"commands":[{"name":"help","usage":"help [--xml] [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The <info>help<\/info> command displays help for a given command:\n\n <info>php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the <comment>--format<\/comment> option:\n\n <info>php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the <info>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|-vv|-vvv","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug","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 <info>list<\/info> command lists all commands:\n\n <info>php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n <info>php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the <comment>--format<\/comment> option:\n\n <info>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 <info>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"]}]}
+{"commands":[{"name":"help","usage":"help [--xml] [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The <info>help<\/info> command displays help for a given command:\n\n <info>php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the <comment>--format<\/comment> option:\n\n <info>php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the <info>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":"txt"},"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|-vv|-vvv","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug","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 <info>list<\/info> command lists all commands:\n\n <info>php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n <info>php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the <comment>--format<\/comment> option:\n\n <info>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 <info>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":"txt"}}}}],"namespaces":[{"id":"_global","commands":["help","list"]}]}
View
4 Tests/Fixtures/application_1.md
@@ -51,7 +51,7 @@ To display the list of available commands, please use the <info>list</info> comm
* Is value required: yes
* Is multiple: no
* Description: To output help in other formats
-* Default: `NULL`
+* Default: `'txt'`
**raw:**
@@ -196,4 +196,4 @@ It's also possible to get raw list of commands (useful for embedding command run
* Is value required: yes
* Is multiple: no
* Description: To output list in other formats
-* Default: `NULL`
+* Default: `'txt'`
View
8 Tests/Fixtures/application_1.xml
@@ -28,7 +28,9 @@
</option>
<option name="--format" shortcut="" accept_value="1" is_value_required="1" is_multiple="0">
<description>To output help in other formats</description>
- <defaults/>
+ <defaults>
+ <default>txt</default>
+ </defaults>
</option>
<option name="--raw" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>To output raw command help</description>
@@ -90,7 +92,9 @@
</option>
<option name="--format" shortcut="" accept_value="1" is_value_required="1" is_multiple="0">
<description>To output list in other formats</description>
- <defaults/>
+ <defaults>
+ <default>txt</default>
+ </defaults>
</option>
</options>
</command>
View
2 Tests/Fixtures/application_2.json
@@ -1 +1 @@
-{"commands":[{"name":"help","usage":"help [--xml] [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The <info>help<\/info> command displays help for a given command:\n\n <info>php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the <comment>--format<\/comment> option:\n\n <info>php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the <info>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|-vv|-vvv","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug","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 <info>list<\/info> command lists all commands:\n\n <info>php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n <info>php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the <comment>--format<\/comment> option:\n\n <info>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 <info>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|-vv|-vvv","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug","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|-vv|-vvv","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug","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"]}]}
+{"commands":[{"name":"help","usage":"help [--xml] [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The <info>help<\/info> command displays help for a given command:\n\n <info>php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the <comment>--format<\/comment> option:\n\n <info>php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the <info>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":"txt"},"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|-vv|-vvv","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug","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 <info>list<\/info> command lists all commands:\n\n <info>php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n <info>php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the <comment>--format<\/comment> option:\n\n <info>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 <info>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":"txt"}}}},{"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|-vv|-vvv","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug","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|-vv|-vvv","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug","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"]}]}
View
4 Tests/Fixtures/application_2.md
@@ -58,7 +58,7 @@ To display the list of available commands, please use the <info>list</info> comm
* Is value required: yes
* Is multiple: no
* Description: To output help in other formats
-* Default: `NULL`
+* Default: `'txt'`
**raw:**
@@ -203,7 +203,7 @@ It's also possible to get raw list of commands (useful for embedding command run
* Is value required: yes
* Is multiple: no
* Description: To output list in other formats
-* Default: `NULL`
+* Default: `'txt'`
descriptor:command1
-------------------
View
8 Tests/Fixtures/application_2.xml
@@ -28,7 +28,9 @@
</option>
<option name="--format" shortcut="" accept_value="1" is_value_required="1" is_multiple="0">
<description>To output help in other formats</description>
- <defaults/>
+ <defaults>
+ <default>txt</default>
+ </defaults>
</option>
<option name="--raw" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>To output raw command help</description>
@@ -90,7 +92,9 @@
</option>
<option name="--format" shortcut="" accept_value="1" is_value_required="1" is_multiple="0">
<description>To output list in other formats</description>
- <defaults/>
+ <defaults>
+ <default>txt</default>
+ </defaults>
</option>
</options>
</command>
View
2 Tests/Fixtures/application_astext1.txt
@@ -17,4 +17,4 @@
<info>help </info> Displays help for a command
<info>list </info> Lists commands
<comment>foo</comment>
- <info>foo:bar </info> The foo:bar command
+ <info>foo:bar </info> The foo:bar command
View
2 Tests/Fixtures/application_astext2.txt
@@ -13,4 +13,4 @@
<info>--no-interaction</info> <info>-n</info> Do not ask any interactive question.
<comment>Available commands for the "foo" namespace:</comment>
- <info>foo:bar </info> The foo:bar command
+ <info>foo:bar </info> The foo:bar command
View
8 Tests/Fixtures/application_asxml1.txt
@@ -28,7 +28,9 @@
</option>
<option name="--format" shortcut="" accept_value="1" is_value_required="1" is_multiple="0">
<description>To output help in other formats</description>
- <defaults/>
+ <defaults>
+ <default>txt</default>
+ </defaults>
</option>
<option name="--raw" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
<description>To output raw command help</description>
@@ -90,7 +92,9 @@
</option>
<option name="--format" shortcut="" accept_value="1" is_value_required="1" is_multiple="0">
<description>To output list in other formats</description>
- <defaults/>
+ <defaults>
+ <default>txt</default>
+ </defaults>
</option>
</options>
</command>
View
3 Tests/Fixtures/application_run2.txt
@@ -7,7 +7,7 @@ Arguments:
Options:
--xml To output help as XML
- --format To output help in other formats
+ --format To output help in other formats (default: "txt")
--raw To output raw command help
--help (-h) Display this help message.
--quiet (-q) Do not output any message.
@@ -27,4 +27,3 @@ Help:
php app/console help --format=xml list
To display the list of available commands, please use the list command.
-
View
3 Tests/Fixtures/application_run3.txt
@@ -7,7 +7,7 @@ Arguments:
Options:
--xml To output list as XML
--raw To output raw command list
- --format To output list in other formats
+ --format To output list in other formats (default: "txt")
Help:
The list command lists all commands:
@@ -25,4 +25,3 @@ Help:
It's also possible to get raw list of commands (useful for embedding command runner):
php app/console list --raw
-

0 comments on commit ec9c103

Please sign in to comment.