Skip to content

[Console] Xml output fix #3569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/Symfony/Component/Console/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,19 @@ public function getDefinition()
return $this->definition;
}

/**
* Gets the InputDefinition to be used to create XML and Text representations of this Command.
*
* Can be overridden to provide the original command representation when it would otherwise
* be changed by merging with the application InputDefinition.
*
* @return InputDefinition An InputDefinition instance
*/
protected function getNativeDefinition()
{
return $this->getDefinition();
}

/**
* Adds an argument.
*
Expand Down Expand Up @@ -531,7 +544,7 @@ public function asText()
$messages[] = '<comment>Aliases:</comment> <info>'.implode(', ', $this->getAliases()).'</info>';
}

$messages[] = $this->definition->asText();
$messages[] = $this->getNativeDefinition()->asText();

if ($help = $this->getProcessedHelp()) {
$messages[] = '<comment>Help:</comment>';
Expand Down Expand Up @@ -572,7 +585,7 @@ public function asXml($asDom = false)
$aliasXML->appendChild($dom->createTextNode($alias));
}

$definition = $this->definition->asXml(true);
$definition = $this->getNativeDefinition()->asXml(true);
$commandXML->appendChild($dom->importNode($definition->getElementsByTagName('arguments')->item(0), true));
$commandXML->appendChild($dom->importNode($definition->getElementsByTagName('options')->item(0), true));

Expand Down
22 changes: 18 additions & 4 deletions src/Symfony/Component/Console/Command/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\Output;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputDefinition;

/**
* ListCommand displays the list of all available commands for the application.
Expand All @@ -31,10 +32,7 @@ class ListCommand extends Command
protected function configure()
{
$this
->setDefinition(array(
new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
new InputOption('xml', null, InputOption::VALUE_NONE, 'To output help as XML'),
))
->setDefinition($this->createDefinition())
->setName('list')
->setDescription('Lists commands')
->setHelp(<<<EOF
Expand All @@ -53,6 +51,14 @@ protected function configure()
);
}

/**
* {@inheritdoc}
*/
protected function getNativeDefinition()
{
return $this->createDefinition();
}

/**
* {@inheritdoc}
*/
Expand All @@ -64,4 +70,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln($this->getApplication()->asText($input->getArgument('namespace')));
}
}

private function createDefinition()
{
return new InputDefinition(array(
new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
new InputOption('xml', null, InputOption::VALUE_NONE, 'To output help as XML'),
));
}
}