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

Erstellt 2y | 19.05.2022, 11:20:18


Melden Sie sich an, um einen Kommentar hinzuzufügen

Andere Beiträge in dieser Gruppe

SymfonyOnline June 2024: LIVE (Component) Experience

SymfonyOnline June 2024 is in less than 2 months: on June 6-7, get ready for the impressive lineup of speakers and topics. Visit here to learn more and don't miss out on this exciting opportuni

26.04.2024, 15:10:09 | Symfony
SymfonyOnline June 2024: The big upgrade. All the way up to Symfony 7 and PHP 8.3

SymfonyOnline June 2024 is in less than 2 months: on June 6-7, get ready for the impressive lineup of speakers and topics. Visit here to learn more and don't miss out on this exciting opportuni

25.04.2024, 13:50:38 | Symfony
SymfonyOnline June 2024: Crafting Elegant Symfony Tests

SymfonyOnline June 2024 is in less than 2 months: on June 6-7, get ready for the impressive lineup of speakers and topics. Visit here to learn more and don't miss out on this exciting opportuni

23.04.2024, 09:40:13 | Symfony
SymfonyLive Berlin 2024: Using container's features to manage complexity

SymfonyLive Berlin 2024 start in 2 months: on June 20-21, get ready for the impressive lineup of speakers and topics. Visit here to learn more and don't miss out on this exciting opportunity!

22.04.2024, 13:10:20 | Symfony
A Week of Symfony #903 (15-21 April 2024)

This week, Symfony continued adding compatibility with the upcoming PHP 8.4 version and also focused on tweaking and polishing the new features of the upcoming Symfony 7.1 version. Meanwhile, we publi

21.04.2024, 07:40:03 | Symfony
SymfonyOnline June 2024: How to Test an External API with 0 Mocks?

SymfonyOnline June 2024 is in less than 2 months: on June 6-7, get ready for the impressive lineup of speakers and topics. Visit here to learn more and don't miss out on this exciting opportuni

19.04.2024, 14:40:02 | Symfony
SymfonyLive Berlin 2024 This is a test: One-click Cypress.IO E2E testing in 45 seconds

SymfonyLive Berlin 2024 start in 2 months: on June 20-21, get ready for the impressive lineup of speakers and topics. Visit here to learn more and don't miss out on this exciting opportunity!

19.04.2024, 10:10:10 | Symfony