-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat: console application - add completion support #8887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -91,7 +91,7 @@ protected function configure(): void | |||
{ | |||
$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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so far good, one question will be placed
@@ -176,7 +178,7 @@ public function getLongVersion(): string | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does one need to run
php-cs-fixer completion -h
manually?
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
@@ -14,7 +14,8 @@ | |||
{ | |||
"name": [ | |||
"*.php", | |||
"*.php8" | |||
"*.php8", | |||
"completion.*" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where are those files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible to detect it's not installed and suggest to install it ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if/how it is possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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