8000 [Console][DX] Fixed ambiguous error message when using a duplicate op… · src-run/symfony@7cb7655 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7cb7655

Browse files
peterrehmfabpot
authored andcommitted
[Console][DX] Fixed ambiguous error message when using a duplicate option shortcut
1 parent 53b7236 commit 7cb7655

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/Symfony/Component/Console/Command/Command.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,14 @@ public function mergeApplicationDefinition($mergeArgs = true)
287287
return;
288288
}
289289

290+
$this->definition->addOptions($this->application->getDefinition()->getOptions());
291+
290292
if ($mergeArgs) {
291293
$currentArguments = $this->definition->getArguments();
292294
$this->definition->setArguments($this->application->getDefinition()->getArguments());
293295
$this->definition->addArguments($currentArguments);
294296
}
295297

296-
$this->definition->addOptions($this->application->getDefinition()->getOptions());
297-
298298
$this->applicationDefinitionMerged = true;
299299
if ($mergeArgs) {
300300
$this->applicationDefinitionMergedWithArgs = true;

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,33 @@ public function testRunReturnsExitCodeOneForExceptionCodeZero()
645645
$this->assertSame(1, $exitCode, '->run() returns exit code 1 when exception code is 0');
646646
}
647647

648+
/**
649+
* @expectedException \LogicException
650+
* @expectedExceptionMessage An option with shortcut "e" already exists.
651+
*/
652+
public function testAddingOptionWithDuplicateShortcut()
653+
{
654+
$dispatcher = new EventDispatcher();
655+
$application = new Application();
656+
$application->setAutoExit(false);
657+
$application->setCatchExceptions(false);
658+
$application->setDispatcher($dispatcher);
659+
660+
$application->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'Environment'));
661+
662+
$application
663+
->register('foo')
664+
->setAliases(['f'])
665+
->setDefinition(array(new InputOption('survey', 'e', InputOption::VALUE_REQUIRED, 'My option with a shortcut.')))
666+
->setCode(function (InputInterface $input, OutputInterface $output) {})
667+
;
668+
6 72DC 69+
$input = new ArrayInput(array('command' => 'foo'));
670+
$output = new NullOutput();
671+
672+
$application->run($input, $output);
673+
}
674+
648675
/**
649676
* @expectedException \LogicException
650677
* @dataProvider getAddingAlreadySetDefinitionElementData

0 commit comments

Comments
 (0)
0