New in Symfony 6.1: Improved Console Autocompletion

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.

https://symfony.com/blog/new-in-symfony-6-1-improved-console-autocompletion?utm_source=Symfony%20Blog%20Feed&utm_medium=feed

Created 2y | May 19, 2022, 11:20:18 AM


Login to add comment

Other posts in this group

New in Symfony 7.1: IsCsrfTokenValid Attribute

Contributed by Yassine Guedidi in #52961 and #54443.

CSRF (Cross-site Request Forgery) attac

May 7, 2024, 8:50:13 AM | Symfony
SymfonyOnline June 2024: Serialization and performance

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

May 6, 2024, 12:20:10 PM | Symfony
New in Symfony 7.1: TypeInfo Component

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-

May 6, 2024, 10:10:10 AM | Symfony
A Week of Symfony #905 (29 April - 5 May 2024)

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

May 5, 2024, 9:10:02 AM | Symfony
SymfonyOnline June 2024: Leveraging Symfony UX in a Real Application

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

May 3, 2024, 4:10:04 PM | Symfony
SymfonyLive Berlin 2024: Enhancing your customers' search experience with Gally

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

May 2, 2024, 2:40:03 PM | Symfony
Symfony 7.1.0-BETA1 released

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/ (
May 2, 2024, 2:40:03 PM | Symfony