Skip to content

Filter and order completions based on input and importance for native completions #5058

@ModProg

Description

@ModProg

While there are some shell specific behaviors for options, e.g. for zsh and fish:

In zsh, options are completed if at least one - is present.

In fish options are completed if the exact number of dashes is present, i.e. one - for a short option and two -- for a long option.

This had an initial implementation at #5057.

We believe that with the additional knowledge available, clap can do better.

Filtering

On an empty current token, complete:

  • If subcommands or positionals are present
    • Subcommands
    • Positional arguments
    • Required pptions (prefer long)
  • else
    • All options (prefer long)

On a single - complete all options, prefer short options where available.

On a double -- complete long options, this would happen either way, so not really a feature. If escaping makes sense (positionals exist), then include just --

In general, aliases are hidden, and only shown if they are the only name of an argument matching the current input.

In all cases, aliases should only show up if the main argument is not being shown

Sorting

Either

  • Alphabetical
  • Display order

Customization

In the future, it could make sense to make both filtering and sorting customizable by the developer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-completionArea: completion generatorC-enhancementCategory: Raise on the bar on expectationsE-easyCall for participation: Experience needed to fix: Easy / not much

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions