[Console] moved --help support to allow proper behavior with other passed options
This commit is contained in:
parent
e9bd48e9b2
commit
fdb4b1fd75
@ -154,23 +154,12 @@ class Application
|
||||
*/
|
||||
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);
|
||||
}
|
||||
@ -200,6 +189,16 @@ class Application
|
||||
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'));
|
||||
|
@ -146,6 +146,18 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
||||
$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.
|
||||
|
Reference in New Issue
Block a user