Skip to content

Commit 98b68c2

Browse files
dirkaholicfabpot
authored andcommitted
[2.2][Console] Add possibility to add new input options to console application
1 parent a086cdc commit 98b68c2

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,18 @@ public function getHelperSet()
221221
return $this->helperSet;
222222
}
223223

224+
/**
225+
* Set an input definition set to be used with this application
226+
*
227+
* @param InputDefinition $definition The input definition
228+
*
229+
* @api
230+
*/
231+
public function setDefinition(InputDefinition $definition)
232+
{
233+
$this->definition = $definition;
234+
}
235+
224236
/**
225237
* Gets the InputDefinition related to this Application.
226238
*

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,30 @@ public function testOverwritingDefaultInputDefinitionOverwritesDefaultValues()
597597

598598
$this->assertTrue($inputDefinition->hasOption('custom'));
599599
}
600+
601+
public function testSettingCustomInputDefinitionOverwritesDefaultValues()
602+
{
603+
$application = new Application();
604+
$application->setAutoExit(false);
605+
$application->setCatchExceptions(false);
606+
607+
$application->setDefinition(new InputDefinition(array(new InputOption('--custom', '-c', InputOption::VALUE_NONE, 'Set the custom input definition.'))));
608+
609+
$inputDefinition = $application->getDefinition();
610+
611+
// check wether the default arguments and options are not returned any more
612+
$this->assertFalse($inputDefinition->hasArgument('command'));
613+
614+
$this->assertFalse($inputDefinition->hasOption('help'));
615+
$this->assertFalse($inputDefinition->hasOption('quiet'));
616+
$this->assertFalse($inputDefinition->hasOption('verbose'));
617+
$this->assertFalse($inputDefinition->hasOption('version'));
618+
$this->assertFalse($inputDefinition->hasOption('ansi'));
619+
$this->assertFalse($inputDefinition->hasOption('no-ansi'));
620+
$this->assertFalse($inputDefinition->hasOption('no-interaction'));
621+
622+
$this->assertTrue($inputDefinition->hasOption('custom'));
623+
}
600624
}
601625

602626
class CustomApplication extends Application
@@ -620,4 +644,4 @@ protected function getDefaultHelperSet()
620644
{
621645
return new HelperSet(array(new FormatterHelper()));
622646
}
623-
}
647+
}

0 commit comments

Comments
 (0)