|
10 | 10 |
|
11 | 11 | class CompletionCommand extends SymfonyCommand
|
12 | 12 | {
|
13 |
| - |
14 | 13 | /**
|
15 | 14 | * @var CompletionHandler
|
16 | 15 | */
|
@@ -49,6 +48,52 @@ public function getNativeDefinition()
|
49 | 48 | return $this->createDefinition();
|
50 | 49 | }
|
51 | 50 |
|
| 51 | + /** |
| 52 | + * Ignore user-defined global options |
| 53 | + * |
| 54 | + * Any global options defined by user-code are meaningless to this command. |
| 55 | + * Options outside of the core defaults are ignored to avoid name and shortcut conflicts. |
| 56 | + */ |
| 57 | + public function mergeApplicationDefinition($mergeArgs = true) |
| 58 | + { |
| 59 | + // Get current application options |
| 60 | + $appDefinition = $this->getApplication()->getDefinition(); |
| 61 | + $originalOptions = $appDefinition->getOptions(); |
| 62 | + |
| 63 | + // Temporarily replace application options with a filtered list |
| 64 | + $appDefinition->setOptions( |
| 65 | + $this->filterApplicationOptions($originalOptions) |
| 66 | + ); |
| 67 | + |
| 68 | + parent::mergeApplicationDefinition($mergeArgs); |
| 69 | + |
| 70 | + // Restore original application options |
| 71 | + $appDefinition->setOptions($originalOptions); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * Reduce the passed list of options to the core defaults (if they exist) |
| 76 | + * |
| 77 | + * @param InputOption[] $appOptions |
| 78 | + * @return InputOption[] |
| 79 | + */ |
| 80 | + protected function filterApplicationOptions(array $appOptions) |
| 81 | + { |
| 82 | + return array_filter($appOptions, function(InputOption $option) { |
| 83 | + static $coreOptions = array( |
| 84 | + 'help' => true, |
| 85 | + 'quiet' => true, |
| 86 | + 'verbose' => true, |
| 87 | + 'version' => true, |
| 88 | + 'ansi' => true, |
| 89 | + 'no-ansi' => true, |
| 90 | + 'no-interaction' => true, |
| 91 | + ); |
| 92 | + |
| 93 | + return isset($coreOptions[$option->getName()]); |
| 94 | + }); |
| 95 | + } |
| 96 | + |
52 | 97 | protected function execute(InputInterface $input, OutputInterface $output)
|
53 | 98 | {
|
54 | 99 | $this->handler = new CompletionHandler($this->getApplication());
|
|
0 commit comments