Skip to content

Unexpected tab completion behaviour with prefixes #5845

@Roy-Orbison

Description

@Roy-Orbison

Bug Report

Describe the current, buggy behavior

When using tab completions, wp-cli's behaviour is inconsistent with all other tab completions I've used, in the case where the word being completed is both an option itself and a prefix of another option. It does not seem to be specific to a shell but, rather, is caused by the potential options wp-cli returns from a given input. I've encountered this using the options beginning with --report or --regex when using wp search-replace but I imagine there are other cases.

Describe how other contributors can replicate this bug

E.g. type this then press Tab a couple of times:

$ wp search-replace --rep

Actual behaviour "eats" the shorter option and completes the longer:

$ wp search-replace --report-changed-only

Describe what you expect as the correct outcome

The expected behaviour is to stop completing and display both options until the user disambiguates with Space, - or Enter:

$ wp search-replace --report
--report               --report-changed-only

To get a like-for-like comparison:

  1. Run the following code in bash to set up a command named wpx for comparison (a safe no-op), and rudimentary completion for it:
    wpx () {
        :
    }
    _wpx () {
        if [ "$3" = "$1" ]; then
            COMPREPLY=( $( compgen -W search-replace -- "$2" ) )
        else
            COMPREPLY=( $( compgen -W '--report --report-changed-only' -- "$2" ) )
        fi
    }
    complete -F _wpx wpx
  2. Enter wpx then press Tab until the output does not change.

Let us know what environment you are running this on

I've experienced this in multiple environments in many versions of wp-cli, but all were on Linux.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions