Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,18 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
CompletionInput::TYPE_ARGUMENT_VALUE === $input->getCompletionType()
&& 'command' === $input->getCompletionName()
) {
$suggestions->suggestValues(array_filter(array_map(function (Command $command) {
return $command->isHidden() ? null : $command->getName();
}, $this->all())));
$commandNames = [];
foreach ($this->all() as $name => $command) {
// skip hidden commands and aliased commands as they already get added below
if ($command->isHidden() || $command->getName() !== $name) {
continue;
}
$commandNames[] = $command->getName();
foreach ($command->getAliases() as $name) {
$commandNames[] = $name;
}
}
$suggestions->suggestValues(array_filter($commandNames));

return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/Console/Command/CompleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
} elseif (
$completionInput->mustSuggestArgumentValuesFor('command')
&& $command->getName() !== $completionInput->getCompletionValue()
&& !\in_array($completionInput->getCompletionValue(), $command->getAliases(), true)
) {
$this->log(' No command found, completing using the Application class.');

// expand shortcut names ("cache:cl<TAB>") into their full name ("cache:clear")
$suggestions->suggestValue($command->getName());
$suggestions->suggestValues(array_filter(array_merge([$command->getName()], $command->getAliases())));
} else {
$command->mergeApplicationDefinition();
$completionInput->bind($command->getDefinition());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ public function testCompleteCommandName(array $input, array $suggestions)

public function provideCompleteCommandNameInputs()
{
yield 'empty' => [['bin/console'], ['help', 'list', 'completion', 'hello']];
yield 'partial' => [['bin/console', 'he'], ['help', 'list', 'completion', 'hello']];
yield 'complete-shortcut-name' => [['bin/console', 'hell'], ['hello']];
yield 'empty' => [['bin/console'], ['help', 'list', 'completion', 'hello', 'ahoy']];
yield 'partial' => [['bin/console', 'he'], ['help', 'list', 'completion', 'hello', 'ahoy']];
yield 'complete-shortcut-name' => [['bin/console', 'hell'], ['hello', 'ahoy']];
yield 'complete-aliases' => [['bin/console', 'ah'], ['hello', 'ahoy']];
}

/**
Expand All @@ -120,6 +121,8 @@ public function provideCompleteCommandInputDefinitionInputs()
{
yield 'definition' => [['bin/console', 'hello', '-'], ['--help', '--quiet', '--verbose', '--version', '--ansi', '--no-interaction']];
yield 'custom' => [['bin/console', 'hello'], ['Fabien', 'Robin', 'Wouter']];
yield 'definition-aliased' => [['bin/console', 'ahoy', '-'], ['--help', '--quiet', '--verbose', '--version', '--ansi', '--no-interaction']];
yield 'custom-aliased' => [['bin/console', 'ahoy'], ['Fabien', 'Robin', 'Wouter']];
}

private function execute(array $input)
Expand All @@ -134,6 +137,7 @@ class CompleteCommandTest_HelloCommand extends Command
public function configure(): void
{
$this->setName('hello')
->setAliases(['ahoy'])
->addArgument('name', InputArgument::REQUIRED)
;
}
Expand Down