Skip to content

Conversation

gharlan
Copy link
Member

@gharlan gharlan commented Jul 24, 2025

@coveralls
Copy link

coveralls commented Jul 24, 2025

Coverage Status

coverage: 94.753% (-0.002%) from 94.755%
when pulling 5a7f8d5 on gharlan:console-completion
into 5bd26f0 on PHP-CS-Fixer:master.

@@ -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()))),
Copy link
Member Author

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.

Copy link
Member Author

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).

Copy link
Member

@keradus keradus left a 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()];
Copy link
Member

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

Copy link
Member Author

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.*"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where are those files?

Copy link
Member Author

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
Copy link
Member

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 ?

Copy link
Member Author

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

Copy link
Member Author

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

@keradus
Copy link
Member

keradus commented Jul 29, 2025

nice one, thanks

@keradus keradus enabled auto-merge (squash) July 29, 2025 22:26
@keradus keradus merged commit 47953b2 into PHP-CS-Fixer:master Jul 29, 2025
32 checks passed
@gharlan gharlan deleted the console-completion branch July 29, 2025 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants