Skip to content

Commit

Permalink
[Console] moved --help support to allow proper behavior with other pa…
Browse files Browse the repository at this point in the history
…ssed options
  • Loading branch information
fabpot committed May 9, 2013
1 parent e9bd48e commit fdb4b1f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/Symfony/Component/Console/Application.php
Expand Up @@ -154,23 +154,12 @@ public function run(InputInterface $input = null, OutputInterface $output = null
*/
public function doRun(InputInterface $input, OutputInterface $output)
{
$name = $this->getCommandName($input);

if (true === $input->hasParameterOption(array('--ansi'))) {
$output->setDecorated(true);
} elseif (true === $input->hasParameterOption(array('--no-ansi'))) {
$output->setDecorated(false);
}

if (true === $input->hasParameterOption(array('--help', '-h'))) {
if (!$name) {
$name = 'help';
$input = new ArrayInput(array('command' => 'help'));
} else {
$this->wantHelps = true;
}
}

if (true === $input->hasParameterOption(array('--no-interaction', '-n'))) {
$input->setInteractive(false);
}
Expand Down Expand Up @@ -200,6 +189,16 @@ public function doRun(InputInterface $input, OutputInterface $output)
return 0;
}

$name = $this->getCommandName($input);
if (true === $input->hasParameterOption(array('--help', '-h'))) {
if (!$name) {
$name = 'help';
$input = new ArrayInput(array('command' => 'help'));
} else {
$this->wantHelps = true;
}
}

if (!$name) {
$name = 'list';
$input = new ArrayInput(array('command' => 'list'));
Expand Down
12 changes: 12 additions & 0 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Expand Up @@ -146,6 +146,18 @@ public function testHasGet()
$this->assertInstanceOf('Symfony\Component\Console\Command\HelpCommand', $command, '->get() returns the help command if --help is provided as the input');
}

public function testSilentHelp()
{
$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);

$tester = new ApplicationTester($application);
$tester->run(array('-h' => true, '-q' => true), array('decorated' => false));

$this->assertEmpty($tester->getDisplay(true));
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The command "foofoo" does not exist.
Expand Down

0 comments on commit fdb4b1f

Please sign in to comment.