feat: console application - add completion support#8887
feat: console application - add completion support#8887keradus merged 13 commits intoPHP-CS-Fixer:masterfrom
Conversation
| $this->setDefinition( | ||
| [ | ||
| new InputArgument('name', InputArgument::REQUIRED, 'Name of rule / set.'), | ||
| new InputArgument('name', InputArgument::REQUIRED, 'Name of rule / set.', null, fn () => array_merge($this->getSetNames(), array_keys($this->getFixers()))), |
There was a problem hiding this comment.
When using symfony/console < 6.1 you will only get completion for command names and option names, not for the argument/option values, because the $suggestedValues param for InputArgument/InputOption didn't exist before.
There was a problem hiding this comment.
So especially when using php-cs-fixer via phar file, because the phar file uses symfony/console 5.4.
Also note that 5.4 supports bash only (fish came with 6.1, and zsh with 6.2).
keradus
left a comment
There was a problem hiding this comment.
so far good, one question will be placed
| protected function getDefaultCommands(): array | ||
| { | ||
| return [new HelpCommand(), new ListCommand()]; | ||
| return [new HelpCommand(), new ListCommand(), new CompleteCommand(), new DumpCompletionCommand()]; |
There was a problem hiding this comment.
does one need to run php-cs-fixer completion -h manually?
if list of commands/params/values change, do they need to re-run it after Fixer upgrade?
if so, we should document to end-user to do it
There was a problem hiding this comment.
does one need to run
php-cs-fixer completion -hmanually?
Everyone who wants to use the completion has to follow the instructions in php-cs-fixer completion -h once.
The paths in the instructions differ depending on your shell (bash, zsh, fish).
if list of commands/params/values change, do they need to re-run it after Fixer upgrade?
No, the installed completion script is dynamic. It uses the CompleteCommand (hidden php-cs-fixer _complete command). So the completions are always "live".
The installed completion script works for all php-cs-fixer executables in all projects (or all php-cs-fixer.phar executables, when installed via php-cs-fixer.phar completion).
The completion scripts are the same for all symfony/console applications: https://github.com/symfony/console/tree/7.3/Resources
if so, we should document to end-user to do it
I'v added a one-liner to the docs now, similar to the one from the composer docs: https://getcomposer.org/doc/03-cli.md#command-line-completion
| "*.php", | ||
| "*.php8" | ||
| "*.php8", | ||
| "completion.*" |
There was a problem hiding this comment.
vendor/symfony/console/Resources/: https://github.com/symfony/console/tree/7.3/Resources
|
|
||
| .. code-block:: console | ||
|
|
||
| php php-cs-fixer.phar completion --help |
There was a problem hiding this comment.
is it possible to detect it's not installed and suggest to install it ?
There was a problem hiding this comment.
I don't know if/how it is possible
There was a problem hiding this comment.
I think it's not really possible to detect
|
nice one, thanks |
See https://symfony.com/doc/current/console/input.html#adding-argument-option-value-completion
and
php-cs-fixer completion -h