feature #13220 [Console] Made output docopt compatible (WouterJ)

This PR was squashed before being merged into the 2.7 branch (closes #13220).

Discussion
----------

[Console] Made output docopt compatible

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #6329
| License       | MIT
| Doc PR        | https://github.com/symfony/symfony-docs/issues/5016

This was harder than I thought. To sum up:

 * The output now follows the [docopt](http://docopt.org/) specification
 * There is a new `addUsage` method to add more usage patterns
 * The handling of spaces in the descriptors is refactored to make it easier to understand and to make it render better (using sprintf's features only made it worse imo)

Todo
---

 * [x] Add test for `addUsage` and friends
 * [x] Add test for multiline descriptions of arguments
 * <s>Convert long descriptions to multiline automatically</s>
 * [ ] Submit a doc PR for `addUsage`

Question
---

The docopt specification suggests we should add these usage patterns:

    %command.name% -h | --help
    %command.name% --version

I didn't do that yet, as I think it'll only makes the output more verbose and it's already pretty obvious.

I've taken some decisions which I don't think everybody agrees with. I'm willing to change it, so feel free to comment :)

/cc @Seldaek

Commits
-------

3910940 [Console] Made output docopt compatible
This commit is contained in:
Fabien Potencier 2015-04-08 07:37:48 +02:00
commit 81bf9108a0
60 changed files with 469 additions and 282 deletions

View File

@ -42,7 +42,8 @@ class Command
private $applicationDefinitionMerged = false;
private $applicationDefinitionMergedWithArgs = false;
private $code;
private $synopsis;
private $synopsis = array();
private $usages = array();
private $helperSet;
/**
@ -219,7 +220,8 @@ class Command
public function run(InputInterface $input, OutputInterface $output)
{
// force the creation of the synopsis before the merge with the app definition
$this->getSynopsis();
$this->getSynopsis(true);
$this->getSynopsis(false);
// add the application arguments and options
$this->mergeApplicationDefinition();
@ -577,15 +579,45 @@ class Command
/**
* Returns the synopsis for the command.
*
* @param bool $short Whether to show the short version of the synopsis (with options folded) or not
*
* @return string The synopsis
*/
public function getSynopsis()
public function getSynopsis($short = false)
{
if (null === $this->synopsis) {
$this->synopsis = trim(sprintf('%s %s', $this->name, $this->definition->getSynopsis()));
$key = $short ? 'short' : 'long';
if (!isset($this->synopsis[$key])) {
$this->synopsis[$key] = trim(sprintf('%s %s', $this->name, $this->definition->getSynopsis($short)));
}
return $this->synopsis;
return $this->synopsis[$key];
}
/**
* Add a command usage example.
*
* @param string $usage The usage, it'll be prefixed with the command name
*/
public function addUsage($usage)
{
if (0 !== strpos($usage, $this->name)) {
$usage = sprintf('%s %s', $this->name, $usage);
}
$this->usages[] = $usage;
return $this;
}
/**
* Returns alternative usages of the command.
*
* @return array
*/
public function getUsages()
{
return $this->usages;
}
/**

View File

@ -102,7 +102,7 @@ class JsonDescriptor extends Descriptor
'name' => $argument->getName(),
'is_required' => $argument->isRequired(),
'is_array' => $argument->isArray(),
'description' => $argument->getDescription(),
'description' => preg_replace('/\s*\R\s*/', ' ', $argument->getDescription()),
'default' => $argument->getDefault(),
);
}
@ -120,7 +120,7 @@ class JsonDescriptor extends Descriptor
'accept_value' => $option->acceptValue(),
'is_value_required' => $option->isValueRequired(),
'is_multiple' => $option->isArray(),
'description' => $option->getDescription(),
'description' => preg_replace('/\s*\R\s*/', ' ', $option->getDescription()),
'default' => $option->getDefault(),
);
}
@ -157,10 +157,9 @@ class JsonDescriptor extends Descriptor
return array(
'name' => $command->getName(),
'usage' => $command->getSynopsis(),
'usage' => array_merge(array($command->getSynopsis()), $command->getUsages(), $command->getAliases()),
'description' => $command->getDescription(),
'help' => $command->getProcessedHelp(),
'aliases' => $command->getAliases(),
'definition' => $this->getInputDefinitionData($command->getNativeDefinition()),
);
}

View File

@ -36,7 +36,7 @@ class MarkdownDescriptor extends Descriptor
.'* Name: '.($argument->getName() ?: '<none>')."\n"
.'* Is required: '.($argument->isRequired() ? 'yes' : 'no')."\n"
.'* Is array: '.($argument->isArray() ? 'yes' : 'no')."\n"
.'* Description: '.($argument->getDescription() ?: '<none>')."\n"
.'* Description: '.preg_replace('/\s*\R\s*/', PHP_EOL.' ', $argument->getDescription() ?: '<none>')."\n"
.'* Default: `'.str_replace("\n", '', var_export($argument->getDefault(), true)).'`'
);
}
@ -53,7 +53,7 @@ class MarkdownDescriptor extends Descriptor
.'* 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"
.'* Description: '.preg_replace('/\s*\R\s*/', PHP_EOL.' ', $option->getDescription() ?: '<none>')."\n"
.'* Default: `'.str_replace("\n", '', var_export($option->getDefault(), true)).'`'
);
}
@ -96,12 +96,14 @@ class MarkdownDescriptor extends Descriptor
$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>')
.'* Usage:'."\n\n"
.array_reduce(array_merge(array($command->getSynopsis()), $command->getAliases(), $command->getUsages()), function ($carry, $usage) {
return $carry .= ' * `'.$usage.'`'."\n";
})
);
if ($help = $command->getProcessedHelp()) {
$this->write("\n\n");
$this->write("\n");
$this->write($help);
}

View File

@ -32,16 +32,19 @@ class TextDescriptor extends Descriptor
protected function describeInputArgument(InputArgument $argument, array $options = array())
{
if (null !== $argument->getDefault() && (!is_array($argument->getDefault()) || count($argument->getDefault()))) {
$default = sprintf('<comment> (default: %s)</comment>', $this->formatDefaultValue($argument->getDefault()));
$default = sprintf('<comment> [default: %s]</comment>', $this->formatDefaultValue($argument->getDefault()));
} else {
$default = '';
}
$nameWidth = isset($options['name_width']) ? $options['name_width'] : strlen($argument->getName());
$totalWidth = isset($options['total_width']) ? $options['total_width'] : strlen($argument->getName());
$spacingWidth = $totalWidth - strlen($argument->getName()) + 2;
$this->writeText(sprintf(" <info>%-${nameWidth}s</info> %s%s",
$this->writeText(sprintf(" <info>%s</info>%s%s%s",
$argument->getName(),
str_replace("\n", "\n".str_repeat(' ', $nameWidth + 2), $argument->getDescription()),
str_repeat(' ', $spacingWidth),
// + 17 = 2 spaces + <info> + </info> + 2 spaces
preg_replace('/\s*\R\s*/', PHP_EOL.str_repeat(' ', $totalWidth + 17), $argument->getDescription()),
$default
), $options);
}
@ -52,18 +55,33 @@ class TextDescriptor extends Descriptor
protected function describeInputOption(InputOption $option, array $options = array())
{
if ($option->acceptValue() && null !== $option->getDefault() && (!is_array($option->getDefault()) || count($option->getDefault()))) {
$default = sprintf('<comment> (default: %s)</comment>', $this->formatDefaultValue($option->getDefault()));
$default = sprintf('<comment> [default: %s]</comment>', $this->formatDefaultValue($option->getDefault()));
} else {
$default = '';
}
$nameWidth = isset($options['name_width']) ? $options['name_width'] : strlen($option->getName());
$nameWithShortcutWidth = $nameWidth - strlen($option->getName()) - 2;
$value = '';
if ($option->acceptValue()) {
$value = '='.strtoupper($option->getName());
$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()),
if ($option->isValueOptional()) {
$value = '['.$value.']';
}
}
$totalWidth = isset($options['total_width']) ? $options['total_width'] : $this->calculateTotalWidthForOptions(array($option));
$synopsis = sprintf('%s%s',
$option->getShortcut() ? sprintf('-%s, ', $option->getShortcut()) : ' ',
sprintf('--%s%s', $option->getName(), $value)
);
$spacingWidth = $totalWidth - strlen($synopsis) + 2;
$this->writeText(sprintf(" <info>%s</info>%s%s%s%s",
$synopsis,
str_repeat(' ', $spacingWidth),
// + 17 = 2 spaces + <info> + </info> + 2 spaces
preg_replace('/\s*\R\s*/', "\n".str_repeat(' ', $totalWidth + 17), $option->getDescription()),
$default,
$option->isArray() ? '<comment> (multiple values allowed)</comment>' : ''
), $options);
@ -74,24 +92,16 @@ class TextDescriptor extends Descriptor
*/
protected function describeInputDefinition(InputDefinition $definition, array $options = array())
{
$nameWidth = 0;
foreach ($definition->getOptions() as $option) {
$nameLength = strlen($option->getName()) + 2;
if ($option->getShortcut()) {
$nameLength += strlen($option->getShortcut()) + 3;
}
$nameWidth = max($nameWidth, $nameLength);
}
$totalWidth = $this->calculateTotalWidthForOptions($definition->getOptions());
foreach ($definition->getArguments() as $argument) {
$nameWidth = max($nameWidth, strlen($argument->getName()));
$totalWidth = max($totalWidth, strlen($argument->getName()));
}
++$nameWidth;
if ($definition->getArguments()) {
$this->writeText('<comment>Arguments:</comment>', $options);
$this->writeText("\n");
foreach ($definition->getArguments() as $argument) {
$this->describeInputArgument($argument, array_merge($options, array('name_width' => $nameWidth)));
$this->describeInputArgument($argument, array_merge($options, array('total_width' => $totalWidth)));
$this->writeText("\n");
}
}
@ -101,11 +111,20 @@ class TextDescriptor extends Descriptor
}
if ($definition->getOptions()) {
$laterOptions = array();
$this->writeText('<comment>Options:</comment>', $options);
$this->writeText("\n");
foreach ($definition->getOptions() as $option) {
$this->describeInputOption($option, array_merge($options, array('name_width' => $nameWidth)));
if (strlen($option->getShortcut()) > 1) {
$laterOptions[] = $option;
continue;
}
$this->writeText("\n");
$this->describeInputOption($option, array_merge($options, array('total_width' => $totalWidth)));
}
foreach ($laterOptions as $option) {
$this->writeText("\n");
$this->describeInputOption($option, array_merge($options, array('total_width' => $totalWidth)));
}
}
}
@ -115,27 +134,26 @@ class TextDescriptor extends Descriptor
*/
protected function describeCommand(Command $command, array $options = array())
{
$command->getSynopsis();
$command->getSynopsis(true);
$command->getSynopsis(false);
$command->mergeApplicationDefinition(false);
$this->writeText('<comment>Usage:</comment>', $options);
$this->writeText("\n");
$this->writeText(' '.$command->getSynopsis(), $options);
$this->writeText("\n");
if (count($command->getAliases()) > 0) {
foreach (array_merge(array($command->getSynopsis(true)), $command->getAliases(), $command->getUsages()) as $usage) {
$this->writeText("\n");
$this->writeText('<comment>Aliases:</comment> <info>'.implode(', ', $command->getAliases()).'</info>', $options);
$this->writeText(' '.$usage, $options);
}
$this->writeText("\n");
if ($definition = $command->getNativeDefinition()) {
$definition = $command->getNativeDefinition();
if ($definition->getOptions() || $definition->getArguments()) {
$this->writeText("\n");
$this->describeInputDefinition($definition, $options);
$this->writeText("\n");
}
$this->writeText("\n");
if ($help = $command->getProcessedHelp()) {
$this->writeText("\n");
$this->writeText('<comment>Help:</comment>', $options);
$this->writeText("\n");
$this->writeText(' '.str_replace("\n", "\n ", $help), $options);
@ -164,27 +182,12 @@ class TextDescriptor extends Descriptor
}
$this->writeText("<comment>Usage:</comment>\n", $options);
$this->writeText(" command [options] [arguments]\n\n", $options);
$this->writeText('<comment>Options:</comment>', $options);
$this->writeText(" command [options] [arguments]\n\n", $options);
$inputOptions = $application->getDefinition()->getOptions();
$this->describeInputDefinition(new InputDefinition($application->getDefinition()->getOptions()), $options);
$width = 0;
foreach ($inputOptions as $option) {
$nameLength = strlen($option->getName()) + 2;
if ($option->getShortcut()) {
$nameLength += strlen($option->getShortcut()) + 3;
}
$width = max($width, $nameLength);
}
++$width;
foreach ($inputOptions as $option) {
$this->writeText("\n", $options);
$this->describeInputOption($option, array_merge($options, array('name_width' => $width)));
}
$this->writeText("\n\n", $options);
$this->writeText("\n");
$this->writeText("\n");
$width = $this->getColumnWidth($description->getCommands());
@ -198,12 +201,13 @@ class TextDescriptor extends Descriptor
foreach ($description->getNamespaces() as $namespace) {
if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
$this->writeText("\n");
$this->writeText('<comment>'.$namespace['id'].'</comment>', $options);
$this->writeText(' <comment>'.$namespace['id'].'</comment>', $options);
}
foreach ($namespace['commands'] as $name) {
$this->writeText("\n");
$this->writeText(sprintf(" <info>%-${width}s</info> %s", $name, $description->getCommand($name)->getDescription()), $options);
$spacingWidth = $width - strlen($name);
$this->writeText(sprintf(" <info>%s</info>%s%s", $name, str_repeat(' ', $spacingWidth), $description->getCommand($name)->getDescription()), $options);
}
}
@ -252,4 +256,27 @@ class TextDescriptor extends Descriptor
return $width + 2;
}
/**
* @param InputOption[] $options
*
* @return int
*/
private function calculateTotalWidthForOptions($options)
{
$totalWidth = 0;
foreach ($options as $option) {
$nameLength = 4 + strlen($option->getName()) + 2; // - + shortcut + , + whitespace + name + --
if ($option->acceptValue()) {
$valueLength = 1 + strlen($option->getName()); // = + value
$valueLength += $option->isValueOptional() ? 2 : 0; // [ + ]
$nameLength += $valueLength;
}
$totalWidth = max($totalWidth, $nameLength);
}
return $totalWidth;
}
}

View File

@ -65,8 +65,11 @@ class XmlDescriptor extends Descriptor
$commandXML->setAttribute('id', $command->getName());
$commandXML->setAttribute('name', $command->getName());
$commandXML->appendChild($usageXML = $dom->createElement('usage'));
$usageXML->appendChild($dom->createTextNode(sprintf($command->getSynopsis(), '')));
$commandXML->appendChild($usagesXML = $dom->createElement('usages'));
foreach (array_merge(array($command->getSynopsis()), $command->getAliases(), $command->getUsages()) as $usage) {
$usagesXML->appendChild($dom->createElement('usage', $usage));
}
$commandXML->appendChild($descriptionXML = $dom->createElement('description'));
$descriptionXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $command->getDescription())));
@ -74,12 +77,6 @@ class XmlDescriptor extends Descriptor
$commandXML->appendChild($helpXML = $dom->createElement('help'));
$helpXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $command->getProcessedHelp())));
$commandXML->appendChild($aliasesXML = $dom->createElement('aliases'));
foreach ($command->getAliases() as $alias) {
$aliasesXML->appendChild($aliasXML = $dom->createElement('alias'));
$aliasXML->appendChild($dom->createTextNode($alias));
}
$definitionXML = $this->getInputDefinitionDocument($command->getNativeDefinition());
$this->appendDocument($commandXML, $definitionXML->getElementsByTagName('definition')->item(0));

View File

@ -391,22 +391,50 @@ class InputDefinition
/**
* Gets the synopsis.
*
* @param bool $short Whether to return the short version (with options foloded) or not
*
* @return string The synopsis
*/
public function getSynopsis()
public function getSynopsis($short = false)
{
$elements = array();
foreach ($this->getOptions() as $option) {
$shortcut = $option->getShortcut() ? sprintf('-%s|', $option->getShortcut()) : '';
$elements[] = sprintf('['.($option->isValueRequired() ? '%s--%s="..."' : ($option->isValueOptional() ? '%s--%s[="..."]' : '%s--%s')).']', $shortcut, $option->getName());
if ($short && $this->getOptions()) {
$elements[] = '[options]';
} elseif (!$short) {
foreach ($this->getOptions() as $option) {
$value = '';
if ($option->acceptValue()) {
$value = sprintf(
' %s%s%s',
$option->isValueOptional() ? '[' : '',
strtoupper($option->getName()),
$option->isValueOptional() ? ']' : ''
);
}
$shortcut = $option->getShortcut() ? sprintf('-%s|', $option->getShortcut()) : '';
$elements[] = sprintf('[%s--%s%s]', $shortcut, $option->getName(), $value);
}
}
if (count($elements) && $this->getArguments()) {
$elements[] = '[--]';
}
foreach ($this->getArguments() as $argument) {
$elements[] = sprintf($argument->isRequired() ? '%s' : '[%s]', $argument->getName().($argument->isArray() ? '1' : ''));
$element = '<'.$argument->getName().'>';
if (!$argument->isRequired()) {
$element = '['.$element.']';
} elseif ($argument->isArray()) {
$element = $element.' ('.$element.')';
}
if ($argument->isArray()) {
$elements[] = sprintf('... [%sN]', $argument->getName());
$element .= '...';
}
$elements[] = $element;
}
return implode(' ', $elements);

View File

@ -154,8 +154,8 @@ class CommandTest extends \PHPUnit_Framework_TestCase
{
$command = new \TestCommand();
$command->addOption('foo');
$command->addArgument('foo');
$this->assertEquals('namespace:name [--foo] [foo]', $command->getSynopsis(), '->getSynopsis() returns the synopsis');
$command->addArgument('bar');
$this->assertEquals('namespace:name [--foo] [--] [<bar>]', $command->getSynopsis(), '->getSynopsis() returns the synopsis');
}
public function testGetHelper()

View File

@ -23,8 +23,10 @@ class HelpCommandTest extends \PHPUnit_Framework_TestCase
$command = new HelpCommand();
$command->setApplication(new Application());
$commandTester = new CommandTester($command);
$commandTester->execute(array('command_name' => 'li'));
$this->assertRegExp('/list \[--xml\] \[--raw\] \[--format="\.\.\."\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command alias');
$commandTester->execute(array('command_name' => 'li'), array('decorated' => false));
$this->assertContains('list [options] [--] [<namespace>]', $commandTester->getDisplay(), '->execute() returns a text help for the given command alias');
$this->assertContains('format=FORMAT', $commandTester->getDisplay(), '->execute() returns a text help for the given command alias');
$this->assertContains('raw', $commandTester->getDisplay(), '->execute() returns a text help for the given command alias');
}
public function testExecuteForCommand()
@ -32,8 +34,10 @@ class HelpCommandTest extends \PHPUnit_Framework_TestCase
$command = new HelpCommand();
$commandTester = new CommandTester($command);
$command->setCommand(new ListCommand());
$commandTester->execute(array());
$this->assertRegExp('/list \[--xml\] \[--raw\] \[--format="\.\.\."\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
$commandTester->execute(array(), array('decorated' => false));
$this->assertContains('list [options] [--] [<namespace>]', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
$this->assertContains('format=FORMAT', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
$this->assertContains('raw', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
}
public function testExecuteForCommandWithXmlOption()
@ -42,7 +46,7 @@ class HelpCommandTest extends \PHPUnit_Framework_TestCase
$commandTester = new CommandTester($command);
$command->setCommand(new ListCommand());
$commandTester->execute(array('--format' => 'xml'));
$this->assertRegExp('/<command/', $commandTester->getDisplay(), '->execute() returns an XML help text if --xml is passed');
$this->assertContains('<command', $commandTester->getDisplay(), '->execute() returns an XML help text if --xml is passed');
}
public function testExecuteForApplicationCommand()
@ -50,7 +54,9 @@ class HelpCommandTest extends \PHPUnit_Framework_TestCase
$application = new Application();
$commandTester = new CommandTester($application->get('help'));
$commandTester->execute(array('command_name' => 'list'));
$this->assertRegExp('/list \[--xml\] \[--raw\] \[--format="\.\.\."\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
$this->assertContains('list [options] [--] [<namespace>]', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
$this->assertContains('format=FORMAT', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
$this->assertContains('raw', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
}
public function testExecuteForApplicationCommandWithXmlOption()
@ -58,7 +64,7 @@ class HelpCommandTest extends \PHPUnit_Framework_TestCase
$application = new Application();
$commandTester = new CommandTester($application->get('help'));
$commandTester->execute(array('command_name' => 'list', '--format' => 'xml'));
$this->assertRegExp('/list \[--xml\] \[--raw\] \[--format="\.\.\."\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
$this->assertRegExp('/<command/', $commandTester->getDisplay(), '->execute() returns an XML help text if --format=xml is passed');
$this->assertContains('list [--xml] [--raw] [--format FORMAT] [--] [&lt;namespace&gt;]', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
$this->assertContains('<command', $commandTester->getDisplay(), '->execute() returns an XML help text if --format=xml is passed');
}
}

View File

@ -22,7 +22,7 @@ class ListCommandTest extends \PHPUnit_Framework_TestCase
$commandTester = new CommandTester($command = $application->get('list'));
$commandTester->execute(array('command' => $command->getName()), array('decorated' => false));
$this->assertRegExp('/help Displays help for a command/', $commandTester->getDisplay(), '->execute() returns a list of available commands');
$this->assertRegExp('/help\s{2,}Displays help for a command/', $commandTester->getDisplay(), '->execute() returns a list of available commands');
}
public function testExecuteListsCommandsWithXmlOption()

View File

@ -96,7 +96,7 @@ abstract class AbstractDescriptorTest extends \PHPUnit_Framework_TestCase
return $data;
}
private function assertDescription($expectedDescription, $describedObject)
protected function assertDescription($expectedDescription, $describedObject)
{
$output = new BufferedOutput(BufferedOutput::VERBOSITY_NORMAL, true);
$this->getDescriptor()->describe($output, $describedObject, array('raw_output' => true));

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Console\Tests\Descriptor;
use Symfony\Component\Console\Descriptor\JsonDescriptor;
use Symfony\Component\Console\Output\BufferedOutput;
class JsonDescriptorTest extends AbstractDescriptorTest
{
@ -24,4 +25,11 @@ class JsonDescriptorTest extends AbstractDescriptorTest
{
return 'json';
}
protected function assertDescription($expectedDescription, $describedObject)
{
$output = new BufferedOutput(BufferedOutput::VERBOSITY_NORMAL, true);
$this->getDescriptor()->describe($output, $describedObject, array('raw_output' => true));
$this->assertEquals(json_decode(trim($expectedDescription), true), json_decode(trim(str_replace(PHP_EOL, "\n", $output->fetch())), true));
}
}

View File

@ -30,6 +30,7 @@ class ObjectsProvider
'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'),
'input_argument_4' => new InputArgument('argument_name', InputArgument::REQUIRED, "multiline\nargument description"),
);
}
@ -40,6 +41,7 @@ class ObjectsProvider
'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()),
'input_option_5' => new InputOption('option_name', 'o', InputOption::VALUE_REQUIRED, "multiline\noption description"),
);
}

View File

@ -23,6 +23,8 @@ class DescriptorCommand2 extends Command
->setName('descriptor:command2')
->setDescription('command 2 description')
->setHelp('command 2 help')
->addUsage('-o|--option_name <argument_name>')
->addUsage('<argument_name>')
->addArgument('argument_name', InputArgument::REQUIRED)
->addOption('option_name', 'o', InputOption::VALUE_NONE)
;

View File

@ -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":"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"]}]}
{"commands":[{"name":"help","usage":["help [--xml] [--format 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.","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 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>","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 File

@ -8,8 +8,9 @@ help
----
* Description: Displays help for a command
* Usage: `help [--xml] [--format="..."] [--raw] [command_name]`
* Aliases: <none>
* Usage:
* `help [--xml] [--format FORMAT] [--raw] [--] [<command_name>]`
The <info>help</info> command displays help for a given command:
@ -137,8 +138,9 @@ list
----
* Description: Lists commands
* Usage: `list [--xml] [--raw] [--format="..."] [namespace]`
* Aliases: <none>
* Usage:
* `list [--xml] [--raw] [--format FORMAT] [--] [<namespace>]`
The <info>list</info> command lists all commands:

View File

@ -1,17 +1,17 @@
<info>Console Tool</info>
<comment>Usage:</comment>
command [options] [arguments]
command [options] [arguments]
<comment>Options:</comment>
<info>--help</info> (-h) Display this help message
<info>--quiet</info> (-q) Do not output any message
<info>--verbose</info> (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
<info>--version</info> (-V) Display this application version
<info>--ansi</info> Force ANSI output
<info>--no-ansi</info> Disable ANSI output
<info>--no-interaction</info> (-n) Do not ask any interactive question
<info>-h, --help</info> Display this help message
<info>-q, --quiet</info> Do not output any message
<info>-V, --version</info> Display this application version
<info> --ansi</info> Force ANSI output
<info> --no-ansi</info> Disable ANSI output
<info>-n, --no-interaction</info> Do not ask any interactive question
<info>-v|vv|vvv, --verbose</info> Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
<comment>Available commands:</comment>
<info>help </info> Displays help for a command
<info>list </info> Lists commands
<info>help</info> Displays help for a command
<info>list</info> Lists commands

View File

@ -2,7 +2,9 @@
<symfony>
<commands>
<command id="help" name="help">
<usage>help [--xml] [--format="..."] [--raw] [command_name]</usage>
<usages>
<usage>help [--xml] [--format FORMAT] [--raw] [--] [&lt;command_name&gt;]</usage>
</usages>
<description>Displays help for a command</description>
<help>The &lt;info&gt;help&lt;/info&gt; command displays help for a given command:
@ -13,7 +15,6 @@
&lt;info&gt;php app/console help --format=xml list&lt;/info&gt;
To display the list of available commands, please use the &lt;info&gt;list&lt;/info&gt; command.</help>
<aliases/>
<arguments>
<argument name="command_name" is_required="0" is_array="0">
<description>The command name</description>
@ -59,7 +60,9 @@
</options>
</command>
<command id="list" name="list">
<usage>list [--xml] [--raw] [--format="..."] [namespace]</usage>
<usages>
<usage>list [--xml] [--raw] [--format FORMAT] [--] [&lt;namespace&gt;]</usage>
</usages>
<description>Lists commands</description>
<help>The &lt;info&gt;list&lt;/info&gt; command lists all commands:
@ -76,7 +79,6 @@
It's also possible to get raw list of commands (useful for embedding command runner):
&lt;info&gt;php app/console list --raw&lt;/info&gt;</help>
<aliases/>
<arguments>
<argument name="namespace" is_required="0" is_array="0">
<description>The namespace name</description>

File diff suppressed because one or more lines are too long

View File

@ -15,8 +15,9 @@ help
----
* Description: Displays help for a command
* Usage: `help [--xml] [--format="..."] [--raw] [command_name]`
* Aliases: <none>
* Usage:
* `help [--xml] [--format FORMAT] [--raw] [--] [<command_name>]`
The <info>help</info> command displays help for a given command:
@ -144,8 +145,9 @@ list
----
* Description: Lists commands
* Usage: `list [--xml] [--raw] [--format="..."] [namespace]`
* Aliases: <none>
* Usage:
* `list [--xml] [--raw] [--format FORMAT] [--] [<namespace>]`
The <info>list</info> command lists all commands:
@ -209,8 +211,11 @@ descriptor:command1
-------------------
* Description: command 1 description
* Usage: `descriptor:command1`
* Aliases: `alias1`, `alias2`
* Usage:
* `descriptor:command1`
* `alias1`
* `alias2`
command 1 help
@ -290,8 +295,11 @@ descriptor:command2
-------------------
* Description: command 2 description
* Usage: `descriptor:command2 [-o|--option_name] argument_name`
* Aliases: <none>
* Usage:
* `descriptor:command2 [-o|--option_name] [--] <argument_name>`
* `descriptor:command2 -o|--option_name <argument_name>`
* `descriptor:command2 <argument_name>`
command 2 help

View File

@ -1,22 +1,22 @@
<info>My Symfony application</info> version <comment>v1.0</comment>
<comment>Usage:</comment>
command [options] [arguments]
command [options] [arguments]
<comment>Options:</comment>
<info>--help</info> (-h) Display this help message
<info>--quiet</info> (-q) Do not output any message
<info>--verbose</info> (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
<info>--version</info> (-V) Display this application version
<info>--ansi</info> Force ANSI output
<info>--no-ansi</info> Disable ANSI output
<info>--no-interaction</info> (-n) Do not ask any interactive question
<info>-h, --help</info> Display this help message
<info>-q, --quiet</info> Do not output any message
<info>-V, --version</info> Display this application version
<info> --ansi</info> Force ANSI output
<info> --no-ansi</info> Disable ANSI output
<info>-n, --no-interaction</info> Do not ask any interactive question
<info>-v|vv|vvv, --verbose</info> Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
<comment>Available commands:</comment>
<info>alias1 </info> command 1 description
<info>alias2 </info> command 1 description
<info>help </info> Displays help for a command
<info>list </info> Lists commands
<comment>descriptor</comment>
<info>descriptor:command1 </info> command 1 description
<info>descriptor:command2 </info> command 2 description
<info>alias1</info> command 1 description
<info>alias2</info> command 1 description
<info>help</info> Displays help for a command
<info>list</info> Lists commands
<comment>descriptor</comment>
<info>descriptor:command1</info> command 1 description
<info>descriptor:command2</info> command 2 description

View File

@ -2,7 +2,9 @@
<symfony name="My Symfony application" version="v1.0">
<commands>
<command id="help" name="help">
<usage>help [--xml] [--format="..."] [--raw] [command_name]</usage>
<usages>
<usage>help [--xml] [--format FORMAT] [--raw] [--] [&lt;command_name&gt;]</usage>
</usages>
<description>Displays help for a command</description>
<help>The &lt;info&gt;help&lt;/info&gt; command displays help for a given command:
@ -13,7 +15,6 @@
&lt;info&gt;php app/console help --format=xml list&lt;/info&gt;
To display the list of available commands, please use the &lt;info&gt;list&lt;/info&gt; command.</help>
<aliases/>
<arguments>
<argument name="command_name" is_required="0" is_array="0">
<description>The command name</description>
@ -59,7 +60,9 @@
</options>
</command>
<command id="list" name="list">
<usage>list [--xml] [--raw] [--format="..."] [namespace]</usage>
<usages>
<usage>list [--xml] [--raw] [--format FORMAT] [--] [&lt;namespace&gt;]</usage>
</usages>
<description>Lists commands</description>
<help>The &lt;info&gt;list&lt;/info&gt; command lists all commands:
@ -76,7 +79,6 @@
It's also possible to get raw list of commands (useful for embedding command runner):
&lt;info&gt;php app/console list --raw&lt;/info&gt;</help>
<aliases/>
<arguments>
<argument name="namespace" is_required="0" is_array="0">
<description>The namespace name</description>
@ -99,13 +101,13 @@
</options>
</command>
<command id="descriptor:command1" name="descriptor:command1">
<usage>descriptor:command1</usage>
<usages>
<usage>descriptor:command1</usage>
<usage>alias1</usage>
<usage>alias2</usage>
</usages>
<description>command 1 description</description>
<help>command 1 help</help>
<aliases>
<alias>alias1</alias>
<alias>alias2</alias>
</aliases>
<arguments/>
<options>
<option name="--help" shortcut="-h" accept_value="0" is_value_required="0" is_multiple="0">
@ -132,10 +134,13 @@
</options>
</command>
<command id="descriptor:command2" name="descriptor:command2">
<usage>descriptor:command2 [-o|--option_name] argument_name</usage>
<usages>
<usage>descriptor:command2 [-o|--option_name] [--] &lt;argument_name&gt;</usage>
<usage>descriptor:command2 -o|--option_name &lt;argument_name&gt;</usage>
<usage>descriptor:command2 &lt;argument_name&gt;</usage>
</usages>
<description>command 2 description</description>
<help>command 2 help</help>
<aliases/>
<arguments>
<argument name="argument_name" is_required="1" is_array="0">
<description></description>

View File

@ -1,20 +1,20 @@
<info>Console Tool</info>
<comment>Usage:</comment>
command [options] [arguments]
command [options] [arguments]
<comment>Options:</comment>
<info>--help</info> (-h) Display this help message
<info>--quiet</info> (-q) Do not output any message
<info>--verbose</info> (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
<info>--version</info> (-V) Display this application version
<info>--ansi</info> Force ANSI output
<info>--no-ansi</info> Disable ANSI output
<info>--no-interaction</info> (-n) Do not ask any interactive question
<info>-h, --help</info> Display this help message
<info>-q, --quiet</info> Do not output any message
<info>-V, --version</info> Display this application version
<info> --ansi</info> Force ANSI output
<info> --no-ansi</info> Disable ANSI output
<info>-n, --no-interaction</info> Do not ask any interactive question
<info>-v|vv|vvv, --verbose</info> Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
<comment>Available commands:</comment>
<info>afoobar </info> The foo:bar command
<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>afoobar</info> The foo:bar command
<info>help</info> Displays help for a command
<info>list</info> Lists commands
<comment>foo</comment>
<info>foo:bar</info> The foo:bar command

View File

@ -1,16 +1,16 @@
<info>Console Tool</info>
<comment>Usage:</comment>
command [options] [arguments]
command [options] [arguments]
<comment>Options:</comment>
<info>--help</info> (-h) Display this help message
<info>--quiet</info> (-q) Do not output any message
<info>--verbose</info> (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
<info>--version</info> (-V) Display this application version
<info>--ansi</info> Force ANSI output
<info>--no-ansi</info> Disable ANSI output
<info>--no-interaction</info> (-n) Do not ask any interactive question
<info>-h, --help</info> Display this help message
<info>-q, --quiet</info> Do not output any message
<info>-V, --version</info> Display this application version
<info> --ansi</info> Force ANSI output
<info> --no-ansi</info> Disable ANSI output
<info>-n, --no-interaction</info> Do not ask any interactive question
<info>-v|vv|vvv, --verbose</info> Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
<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 File

@ -2,7 +2,9 @@
<symfony>
<commands>
<command id="help" name="help">
<usage>help [--xml] [--format="..."] [--raw] [command_name]</usage>
<usages>
<usage>help [--xml] [--format FORMAT] [--raw] [--] [&lt;command_name&gt;]</usage>
</usages>
<description>Displays help for a command</description>
<help>The &lt;info&gt;help&lt;/info&gt; command displays help for a given command:
@ -13,7 +15,6 @@
&lt;info&gt;php app/console help --format=xml list&lt;/info&gt;
To display the list of available commands, please use the &lt;info&gt;list&lt;/info&gt; command.</help>
<aliases />
<arguments>
<argument name="command_name" is_required="0" is_array="0">
<description>The command name</description>
@ -59,7 +60,9 @@
</options>
</command>
<command id="list" name="list">
<usage>list [--xml] [--raw] [--format="..."] [namespace]</usage>
<usages>
<usage>list [--xml] [--raw] [--format FORMAT] [--] [&lt;namespace&gt;]</usage>
</usages>
<description>Lists commands</description>
<help>The &lt;info&gt;list&lt;/info&gt; command lists all commands:
@ -76,7 +79,6 @@
It's also possible to get raw list of commands (useful for embedding command runner):
&lt;info&gt;php app/console list --raw&lt;/info&gt;</help>
<aliases/>
<arguments>
<argument name="namespace" is_required="0" is_array="0">
<description>The namespace name</description>
@ -99,12 +101,12 @@
</options>
</command>
<command id="foo:bar" name="foo:bar">
<usage>foo:bar</usage>
<usages>
<usage>foo:bar</usage>
<usage>afoobar</usage>
</usages>
<description>The foo:bar command</description>
<help/>
<aliases>
<alias>afoobar</alias>
</aliases>
<arguments/>
<options>
<option name="--help" shortcut="-h" accept_value="0" is_value_required="0" is_multiple="0">

View File

@ -2,12 +2,12 @@
<symfony>
<commands namespace="foo">
<command id="foo:bar" name="foo:bar">
<usage>foo:bar</usage>
<usages>
<usage>foo:bar</usage>
<usage>afoobar</usage>
</usages>
<description>The foo:bar command</description>
<help/>
<aliases>
<alias>afoobar</alias>
</aliases>
<arguments/>
<options>
<option name="--help" shortcut="-h" accept_value="0" is_value_required="0" is_multiple="0">

View File

@ -6,6 +6,6 @@
list [--xml] [--raw] [--format="..."] [namespace]
list [--xml] [--raw] [--format FORMAT] [--] [<namespace>]

View File

@ -1,17 +1,17 @@
Console Tool
Usage:
command [options] [arguments]
command [options] [arguments]
Options:
--help (-h) Display this help message
--quiet (-q) Do not output any message
--verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
--version (-V) Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
--no-interaction (-n) Do not ask any interactive question
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
help Displays help for a command
list Lists commands
help Displays help for a command
list Lists commands

View File

@ -1,21 +1,21 @@
Usage:
help [--xml] [--format="..."] [--raw] [command_name]
help [options] [--] [<command_name>]
Arguments:
command The command to execute
command_name The command name (default: "help")
command The command to execute
command_name The command name [default: "help"]
Options:
--xml To output help as XML
--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
--verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
--version (-V) Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
--no-interaction (-n) Do not ask any interactive question
--xml To output help as XML
--format=FORMAT To output help in other formats [default: "txt"]
--raw To output raw command help
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Help:
The help command displays help for a given command:

View File

@ -1,13 +1,13 @@
Usage:
list [--xml] [--raw] [--format="..."] [namespace]
list [options] [--] [<namespace>]
Arguments:
namespace The namespace name
namespace The namespace name
Options:
--xml To output list as XML
--raw To output raw command list
--format To output list in other formats (default: "txt")
--xml To output list as XML
--raw To output raw command list
--format=FORMAT To output list in other formats [default: "txt"]
Help:
The list command lists all commands:

View File

@ -1 +1 @@
{"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", "alias1", "alias2"],"description":"command 1 description","help":"command 1 help","definition":{"arguments":[],"options":[]}}

View File

@ -2,7 +2,10 @@ descriptor:command1
-------------------
* Description: command 1 description
* Usage: `descriptor:command1`
* Aliases: `alias1`, `alias2`
* Usage:
* `descriptor:command1`
* `alias1`
* `alias2`
command 1 help

View File

@ -1,7 +1,7 @@
<comment>Usage:</comment>
descriptor:command1
<comment>Aliases:</comment> <info>alias1, alias2</info>
descriptor:command1
alias1
alias2
<comment>Help:</comment>
command 1 help

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<command id="descriptor:command1" name="descriptor:command1">
<usage>descriptor:command1</usage>
<usages>
<usage>descriptor:command1</usage>
<usage>alias1</usage>
<usage>alias2</usage>
</usages>
<description>command 1 description</description>
<help>command 1 help</help>
<aliases>
<alias>alias1</alias>
<alias>alias2</alias>
</aliases>
<arguments/>
<options/>
</command>

View File

@ -1 +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}}}}
{"name":"descriptor:command2","usage":["descriptor:command2 [-o|--option_name] [--] <argument_name>", "descriptor:command2 -o|--option_name <argument_name>", "descriptor:command2 <argument_name>"],"description":"command 2 description","help":"command 2 help","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}}}}

View File

@ -2,8 +2,11 @@ descriptor:command2
-------------------
* Description: command 2 description
* Usage: `descriptor:command2 [-o|--option_name] argument_name`
* Aliases: <none>
* Usage:
* `descriptor:command2 [-o|--option_name] [--] <argument_name>`
* `descriptor:command2 -o|--option_name <argument_name>`
* `descriptor:command2 <argument_name>`
command 2 help

View File

@ -1,11 +1,13 @@
<comment>Usage:</comment>
descriptor:command2 [-o|--option_name] argument_name
descriptor:command2 [options] [--] <argument_name>
descriptor:command2 -o|--option_name <argument_name>
descriptor:command2 <argument_name>
<comment>Arguments:</comment>
<info>argument_name </info>
<info>argument_name</info>
<comment>Options:</comment>
<info>--option_name</info> (-o)
<info>-o, --option_name</info>
<comment>Help:</comment>
command 2 help

View File

@ -1,9 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<command id="descriptor:command2" name="descriptor:command2">
<usage>descriptor:command2 [-o|--option_name] argument_name</usage>
<usages>
<usage>descriptor:command2 [-o|--option_name] [--] &lt;argument_name&gt;</usage>
<usage>descriptor:command2 -o|--option_name &lt;argument_name&gt;</usage>
<usage>descriptor:command2 &lt;argument_name&gt;</usage>
</usages>
<description>command 2 description</description>
<help>command 2 help</help>
<aliases/>
<arguments>
<argument name="argument_name" is_required="1" is_array="0">
<description></description>

View File

@ -1,18 +1,18 @@
<comment>Usage:</comment>
namespace:name
namespace:name
name
<comment>Aliases:</comment> <info>name</info>
<comment>Arguments:</comment>
<info>command </info> The command to execute
<info>command</info> The command to execute
<comment>Options:</comment>
<info>--help</info> (-h) Display this help message
<info>--quiet</info> (-q) Do not output any message
<info>--verbose</info> (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
<info>--version</info> (-V) Display this application version
<info>--ansi</info> Force ANSI output
<info>--no-ansi</info> Disable ANSI output
<info>--no-interaction</info> (-n) Do not ask any interactive question
<info>-h, --help</info> Display this help message
<info>-q, --quiet</info> Do not output any message
<info>-V, --version</info> Display this application version
<info> --ansi</info> Force ANSI output
<info> --no-ansi</info> Disable ANSI output
<info>-n, --no-interaction</info> Do not ask any interactive question
<info>-v|vv|vvv, --verbose</info> Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
<comment>Help:</comment>
help

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<command id="namespace:name" name="namespace:name">
<usage>namespace:name</usage>
<usages>
<usage>namespace:name</usage>
<usage>name</usage>
</usages>
<description>description</description>
<help>help</help>
<aliases>
<alias>name</alias>
</aliases>
<arguments>
<argument name="command" is_required="1" is_array="0">
<description>The command to execute</description>

View File

@ -1,11 +1,11 @@
<comment>Arguments:</comment>
<info>foo </info> The foo argument
<info>baz </info> The baz argument<comment> (default: true)</comment>
<info>bar </info> The bar argument<comment> (default: ["http://foo.com/"])</comment>
<info>foo</info> The foo argument
<info>baz</info> The baz argument<comment> [default: true]</comment>
<info>bar</info> The bar argument<comment> [default: ["http://foo.com/"]]</comment>
<comment>Options:</comment>
<info>--foo</info> (-f) The foo option
<info>--baz</info> The baz option<comment> (default: false)</comment>
<info>--bar</info> (-b) The bar option<comment> (default: "bar")</comment>
<info>--qux</info> The qux option<comment> (default: ["http://foo.com/","bar"])</comment><comment> (multiple values allowed)</comment>
<info>--qux2</info> The qux2 option<comment> (default: {"foo":"bar"})</comment><comment> (multiple values allowed)</comment>
<info>-f, --foo=FOO</info> The foo option
<info> --baz[=BAZ]</info> The baz option<comment> [default: false]</comment>
<info>-b, --bar[=BAR]</info> The bar option<comment> [default: "bar"]</comment>
<info> --qux[=QUX]</info> The qux option<comment> [default: ["http://foo.com/","bar"]]</comment><comment> (multiple values allowed)</comment>
<info> --qux2[=QUX2]</info> The qux2 option<comment> [default: {"foo":"bar"}]</comment><comment> (multiple values allowed)</comment>

View File

@ -1 +1 @@
<info>argument_name</info>
<info>argument_name</info>

View File

@ -1 +1 @@
<info>argument_name</info> argument description
<info>argument_name</info> argument description

View File

@ -1 +1 @@
<info>argument_name</info> argument description<comment> (default: "default_value")</comment>
<info>argument_name</info> argument description<comment> [default: "default_value"]</comment>

View File

@ -0,0 +1 @@
{"name":"argument_name","is_required":true,"is_array":false,"description":"multiline argument description","default":null}

View File

@ -0,0 +1,8 @@
**argument_name:**
* Name: argument_name
* Is required: yes
* Is array: no
* Description: multiline
argument description
* Default: `NULL`

View File

@ -0,0 +1,2 @@
<info>argument_name</info> multiline
argument description

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<argument name="argument_name" is_required="1" is_array="0">
<description>multiline
argument description</description>
<defaults/>
</argument>

View File

@ -1,2 +1,2 @@
<comment>Arguments:</comment>
<info>argument_name </info>
<info>argument_name</info>

View File

@ -1,2 +1,2 @@
<comment>Options:</comment>
<info>--option_name</info> (-o)
<info>-o, --option_name</info>

View File

@ -1,5 +1,5 @@
<comment>Arguments:</comment>
<info>argument_name </info>
<info>argument_name</info>
<comment>Options:</comment>
<info>--option_name</info> (-o)
<info>-o, --option_name</info>

View File

@ -1 +1 @@
<info>--option_name</info> (-o)
<info>-o, --option_name</info>

View File

@ -1 +1 @@
<info>--option_name</info> (-o) option description<comment> (default: "default_value")</comment>
<info>-o, --option_name[=OPTION_NAME]</info> option description<comment> [default: "default_value"]</comment>

View File

@ -1 +1 @@
<info>--option_name</info> (-o) option description
<info>-o, --option_name=OPTION_NAME</info> option description

View File

@ -1 +1 @@
<info>--option_name</info> (-o) option description<comment> (multiple values allowed)</comment>
<info>-o, --option_name[=OPTION_NAME]</info> option description<comment> (multiple values allowed)</comment>

View File

@ -0,0 +1 @@
{"name":"--option_name","shortcut":"-o","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"multiline option description","default":null}

View File

@ -0,0 +1,10 @@
**option_name:**
* Name: `--option_name`
* Shortcut: `-o`
* Accept value: yes
* Is value required: yes
* Is multiple: no
* Description: multiline
option description
* Default: `NULL`

View File

@ -0,0 +1,2 @@
<info>-o, --option_name=OPTION_NAME</info> multiline
option description

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<option name="--option_name" shortcut="-o" accept_value="1" is_value_required="1" is_multiple="0">
<description>multiline
option description</description>
<defaults/>
</option>

View File

@ -352,25 +352,35 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
$this->assertSame($defaults, $definition->getOptionDefaults(), '->getOptionDefaults() returns the default values for all options');
}
public function testGetSynopsis()
/**
* @dataProvider getGetSynopsisData
*/
public function testGetSynopsis(InputDefinition $definition, $expectedSynopsis, $message = null)
{
$definition = new InputDefinition(array(new InputOption('foo')));
$this->assertEquals('[--foo]', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
$definition = new InputDefinition(array(new InputOption('foo', 'f')));
$this->assertEquals('[-f|--foo]', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
$definition = new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED)));
$this->assertEquals('[-f|--foo="..."]', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
$definition = new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL)));
$this->assertEquals('[-f|--foo[="..."]]', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
$this->assertEquals($expectedSynopsis, $definition->getSynopsis(), $message ? '->getSynopsis() '.$message : '');
}
$definition = new InputDefinition(array(new InputArgument('foo')));
$this->assertEquals('[foo]', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
$definition = new InputDefinition(array(new InputArgument('foo', InputArgument::REQUIRED)));
$this->assertEquals('foo', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
$definition = new InputDefinition(array(new InputArgument('foo', InputArgument::IS_ARRAY)));
$this->assertEquals('[foo1] ... [fooN]', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
$definition = new InputDefinition(array(new InputArgument('foo', InputArgument::REQUIRED | InputArgument::IS_ARRAY)));
$this->assertEquals('foo1 ... [fooN]', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
public function getGetSynopsisData()
{
return array(
array(new InputDefinition(array(new InputOption('foo'))), '[--foo]', 'puts optional options in square brackets'),
array(new InputDefinition(array(new InputOption('foo', 'f'))), '[-f|--foo]', 'separates shortcut with a pipe'),
array(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))), '[-f|--foo FOO]', 'uses shortcut as value placeholder'),
array(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL))), '[-f|--foo [FOO]]', 'puts optional values in square brackets'),
array(new InputDefinition(array(new InputArgument('foo', InputArgument::REQUIRED))), '<foo>', 'puts arguments in angle brackets'),
array(new InputDefinition(array(new InputArgument('foo'))), '[<foo>]', 'puts optional arguments in square brackets'),
array(new InputDefinition(array(new InputArgument('foo', InputArgument::IS_ARRAY))), '[<foo>]...', 'uses an ellipsis for array arguments'),
array(new InputDefinition(array(new InputArgument('foo', InputArgument::REQUIRED | InputArgument::IS_ARRAY))), '<foo> (<foo>)...', 'uses parenthesis and ellipsis for required array arguments'),
array(new InputDefinition(array(new InputOption('foo'), new InputArgument('foo', InputArgument::REQUIRED))), '[--foo] [--] <foo>', 'puts [--] between options and arguments'),
);
}
public function testGetShortSynopsis()
{
$definition = new InputDefinition(array(new InputOption('foo'), new InputOption('bar'), new InputArgument('cat')));
$this->assertEquals('[options] [--] [<cat>]', $definition->getSynopsis(true), '->getSynopsis(true) groups options in [options]');
}
/**
@ -390,6 +400,7 @@ class InputDefinitionTest extends \PHPUnit_Framework_TestCase
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');
}

View File

@ -986,6 +986,13 @@ HTML;
);
}
public function testCountOfNestedElements()
{
$crawler = new Crawler('<html><body><ul><li>List item 1<ul><li>Sublist item 1</li><li>Sublist item 2</ul></li></ul></body></html>');
$this->assertCount(1, $crawler->filter('li:contains("List item 1")'));
}
public function createTestCrawler($uri = null)
{
$dom = new \DOMDocument();