Skip to content

Conversation

@dereuromark
Copy link
Member

@dereuromark dereuromark commented Nov 26, 2025

Summary

The completion commands mode was outputting both short names and plugin-prefixed aliases (e.g., both migrations and migrations.migrations), causing duplicate suggestions in shell autocompletion.

This change filters out plugin-prefixed command names (those containing .) from the commands output, showing only the primary short form.

Before:

help version migrations migrations.migrations migrations.bake test_helper.linter linter ...

After:

help version migrations linter ...

The subcommands and options modes still support plugin-prefixed names for backward compatibility when explicitly used.

Changes

  • Modified getCommands() to skip command names containing .
  • Updated test to not expect plugin-prefixed aliases in output
  • Added new test testCommandsExcludesPluginAliases() to verify the fix

This is a critical fix needed to get CLI autocomplete to work properly:

hooks:
  post-start:
    - exec: |
        cat >> ~/.bashrc << 'EOF'
        alias c="composer"
        alias cake="bin/cake"
        _cake() {
          local cur prev
          COMPREPLY=()
          cur="${COMP_WORDS[COMP_CWORD]}"
          prev="${COMP_WORDS[COMP_CWORD-1]}"
          if [[ ${COMP_CWORD} == 1 ]]; then
            COMPREPLY=( $(compgen -W "$(bin/cake completion commands 2>/dev/null)" -- ${cur}) )
          elif [[ ${COMP_CWORD} == 2 ]]; then
            COMPREPLY=( $(compgen -W "$(bin/cake completion subcommands ${prev} 2>/dev/null)" -- ${cur}) )
          else
            COMPREPLY=( $(compgen -W "$(bin/cake completion options ${COMP_WORDS[1]} ${COMP_WORDS[2]} 2>/dev/null)" -- ${cur}) )
          fi
        }
        complete -F _cake bin/cake
        complete -F _cake cake
        EOF

//EDIT
I changed it so in verbose mode it retains current behavior if really needed (even though doubtful).

@dereuromark dereuromark added this to the 5.3.0 milestone Nov 26, 2025
Plugin-prefixed aliases are now excluded by default to avoid duplicate
completions. Use verbose mode (-v) to include all aliases.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@dereuromark dereuromark force-pushed the fix-completion-command-aliases branch from a0179a1 to 03af26e Compare November 26, 2025 16:34
Comment on lines 102 to 103
// Plugin-prefixed aliases should not be in the output
// as they are duplicates of the short form
Copy link
Member

Choose a reason for hiding this comment

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

That's not always true though. If multiple plugins have the same command, only the names containing . will work consistently.

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 see.
But we could detect the true duplicates at least couldnt we?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we could compare the values and find duplicates.

@dereuromark dereuromark marked this pull request as draft November 28, 2025 15:01
@dereuromark
Copy link
Member Author

What changed:

  1. src/Command/CompletionCommand.php:
    - Instead of filtering out ALL plugin-prefixed aliases (commands with . in the name), now only filters out true duplicates
    - A "true duplicate" is when the plugin-prefixed alias (e.g., test_plugin_two.unique) resolves to the same command class as the short form (e.g., unique)
    - When multiple plugins have commands with the same name (e.g., sample in App and test_plugin.sample in TestPlugin), both are shown since they're
    different classes
  2. tests/TestCase/Command/CompletionCommandTest.php:
    - Updated the test to reflect the new behavior
    - True duplicates like test_plugin.example, test_plugin_two.unique, test_plugin_two.welcome are excluded
    - Non-duplicates like test_plugin.sample and test_plugin_two.example are now correctly included

@dereuromark dereuromark marked this pull request as ready for review December 4, 2025 05:01
@dereuromark dereuromark added the needs squashing The pull request should be squashed before merging label Dec 4, 2025
@dereuromark
Copy link
Member Author

dereuromark commented Dec 4, 2025

Note sure if this is correct, though, it outputs again a bit more than I would like:

before:

help version cache completion counter_cache i18n plugin routes schema_cache server migrations migrations.migrations bake migrations.bake inflect tools.inflect healthcheck maintenance_mode current_config db db_integrity db_data db_backup user reset mail_check cli_test page_cache asset_compress tiny_auth database_logs queue scheduler dto bootstrap expose expose.expose audit_stash file_storage state_machine.bake state_machine state_machine.state_machine annotate generate illuminate benchmark fixture_check test_helper.fixture_check linter test_helper.linter twig-view

after:

help version cache completion counter_cache i18n plugin routes schema_cache server migrations bake migrations.bake inflect healthcheck maintenance_mode current_config db db_integrity db_data db_backup user reset mail_check cli_test page_cache asset_compress tiny_auth database_logs queue scheduler dto bootstrap expose expose.expose audit_stash file_storage state_machine.bake state_machine state_machine.state_machine annotate generate illuminate benchmark fixture_check linter twig-view

it correctly filters "migrations.migrations", but all those extra bake ones dont seem necessary either IMO.

Comment on lines -73 to -75
'test_plugin.example',
'test_plugin.sample',
'test_plugin_two.example',
Copy link
Member

Choose a reason for hiding this comment

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

Now there isn't any example command in the completion list. Should example be added here?

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right, fixed that up.

@dereuromark dereuromark force-pushed the fix-completion-command-aliases branch from 5f9a936 to eac0677 Compare December 9, 2025 02:28
@markstory markstory merged commit 00ca91c into cakephp:5.x Dec 10, 2025
15 checks passed
@dereuromark dereuromark deleted the fix-completion-command-aliases branch January 12, 2026 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

defect needs squashing The pull request should be squashed before merging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants