In Symfony 5.4 we introduced console autocompletion for the argument names, option names and option values of any command created with the Symfony Console component. In Symfony 6.1 we're improving it with new features.
Autocompletion for Fish Shell
Contributed by Guillaume Aveline
in #43641.
Autocompletion works differently depending on your shell. Previously we only supported autocompletion in Bash shell. Starting from Symfony 6.1 we also support Fish shell, which is popular among many developers. To enable autocompletion in your Fish shell, you only need to run the following command once and then source the file:
$ php bin/console completion fish >> ~/.config/fish/completions/sf_console.fish
Completion Values in Input Definitions
Contributed by Jérôme Tamarelle
in #44948.
Autocompletion is currently based on defining a method called complete() in your command. There you can provide the possible values of nay of the command arguments and options. In Symfony 6.1 you can also define autocompletion values directly in the command input definition:
new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help', function () {
// here we return the name of all app commands
return array_keys((new ApplicationDescription($this->getApplication()))->getCommands());
}),
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt', function () { // here we return an array of possible values defined somewhere return (new DescriptorHelper())->getFormats(); }),
// when using addOption() and addArgument() you can also provide autocompletion ->addArgument('shell', InputArgument::OPTIONAL, '...', null, fn () => $this->getSupportedShells())
Sponsor the Symfony project.
Login to add comment
Other posts in this group
Contributed by Yassine Guedidi in #52961 and #54443.
CSRF (Cross-site Request Forgery) attac
SymfonyOnline June 2024 is just around the corner and will start on:
June 4-5: Workshop days. It is possible to attend 1 two-day training or 2 one-day trainings! June 6-7: Online conference
This is the first article of the series that shows the most important new features introduced by Symfony 7.1, which will be released at the end of May 2024.… https://symfony.com/blog/new-in-symfony-7-
This week, Symfony 5.4.39, 6.4.7 and 7.0.7 maintenance versions were released. In addition, Symfony published the first beta of Symfony 7.1 so you can test it in your own applications before the final
SymfonyOnline June 2024 is just around the corner and will start on:
June 4-5: Workshop days. It is possible to attend 1 two-day training or 2 one-day trainings! June 6-7: Online conference
SymfonyLive Berlin 2024 is just around the corner and will start on June 20-21. Get ready for the impressive lineup of speakers and topics. Visit here to more details and don't miss out on this
Symfony 7.1.0-BETA1 has just been released. Here is the list of the most important changes since 7.0:
feature #54818 [Translation] Crowdin is backing its translation bridge, thanks to them! \o/ (