Skip to content

[HelpCommand] reset command definition if instance of self #9266

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

Closed
wants to merge 4 commits into from
Closed
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: 13 additions & 4 deletions src/Symfony/Component/Console/Command/HelpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ protected function configure()

$this
->setName('help')
->setDefinition(array(
new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'),
new InputOption('xml', null, InputOption::VALUE_NONE, 'To output help as XML'),
))
->setDefinition($this->getInputDefinition())
->setDescription('Displays help for a command')
->setHelp(<<<EOF
The <info>%command.name%</info> command displays help for a given command:
Expand Down Expand Up @@ -74,6 +71,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->command = $this->getApplication()->find($input->getArgument('command_name'));
}

if ($this->command instanceof self) {
$this->command->setDefinition($this->getInputDefinition());
}

if ($input->getOption('xml')) {
$output->writeln($this->command->asXml(), OutputInterface::OUTPUT_RAW);
} else {
Expand All @@ -82,4 +83,12 @@ protected function execute(InputInterface $input, OutputInterface $output)

$this->command = null;
}

private function getInputDefinition()
{
return array(
new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'),
new InputOption('xml', null, InputOption::VALUE_NONE, 'To output help as XML'),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ Usage:
help [--xml] [command_name]

Arguments:
command The command to execute
command_name The command name (default: "help")

Options:
Expand Down