Skip to content

Commit fdb4b1f

Browse files
committed
[Console] moved --help support to allow proper behavior with other passed options
1 parent e9bd48e commit fdb4b1f

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -154,23 +154,12 @@ public function run(InputInterface $input = null, OutputInterface $output = null
154154
*/
155155
public function doRun(InputInterface $input, OutputInterface $output)
156156
{
157-
$name = $this->getCommandName($input);
158-
159157
if (true === $input->hasParameterOption(array('--ansi'))) {
160158
$output->setDecorated(true);
161159
} elseif (true === $input->hasParameterOption(array('--no-ansi'))) {
162160
$output->setDecorated(false);
163161
}
164162

165-
if (true === $input->hasParameterOption(array('--help', '-h'))) {
166-
if (!$name) {
167-
$name = 'help';
168-
$input = new ArrayInput(array('command' => 'help'));
169-
} else {
170-
$this->wantHelps = true;
171-
}
172-
}
173-
174163
if (true === $input->hasParameterOption(array('--no-interaction', '-n'))) {
175164
$input->setInteractive(false);
176165
}
@@ -200,6 +189,16 @@ public function doRun(InputInterface $input, OutputInterface $output)
200189
return 0;
201190
}
202191

192+
$name = $this->getCommandName($input);
193+
if (true === $input->hasParameterOption(array('--help', '-h'))) {
194+
if (!$name) {
195+
$name = 'help';
196+
$input = new ArrayInput(array('command' => 'help'));
197+
} else {
198+
$this->wantHelps = true;
199+
}
200+
}
201+
203202
if (!$name) {
204203
$name = 'list';
205204
$input = new ArrayInput(array('command' => 'list'));

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,18 @@ public function testHasGet()
146146
$this->assertInstanceOf('Symfony\Component\Console\Command\HelpCommand', $command, '->get() returns the help command if --help is provided as the input');
147147
}
148148

149+
public function testSilentHelp()
150+
{
151+
$application = new Application();
152+
$application->setAutoExit(false);
153+
$application->setCatchExceptions(false);
154+
155+
$tester = new ApplicationTester($application);
156+
$tester->run(array('-h' => true, '-q' => true), array('decorated' => false));
157+
158+
$this->assertEmpty($tester->getDisplay(true));
159+
}
160+
149161
/**
150162
* @expectedException \InvalidArgumentException
151163
* @expectedExceptionMessage The command "foofoo" does not exist.

0 commit comments

Comments
 (0)