Symfony News

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

Guillaume Aveline

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

Jérôme Tamarelle

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.


About us

What a Symfony developer should know about the framework: News, Jobs, Tweets, Events, Videos,...

Resources

Find us on Twitter

Find us on Facebook