Skip to content

Make completions for subcommands easier to add #7107

@sudormrfbin

Description

@sudormrfbin

The current way to add completions for subcommands of a command, as can be seen from the default completions in share/completions, is to define functions like __fish_cmdname_needs_subcommand and __fish_cmdname_using_subcommand and then use them as conditions like so:

# main subcommands
complete -c cmdname -n "__fish_cmdname_needs_subcommand" -a "subcmd1"
complete -c cmdname -n "__fish_cmdname_needs_subcommand" -a "subcmd2"
# completions for options of subcommands
complete -c cmdname -n "__fish_cmdname_using_subcommand subcmd1" -l subcmd1-specific-option

This leads to a lot of duplicated code and could be buggy. Adding a --subcommand flag to the complete command to specify subcommands and options exclusive to them could be very useful. Something like this:

complete -c cmdname --subcommand subcmd1
complete -c cmdname --subcommand subcmd1 -l subcmd1-specific-option

Or maybe the -c flag itself can take care of the subcommands, which IMO is more readable and intuitive, especially in the case for subcommands of subcommands:

complete -c 'git remote' -d 'Manage set of tracked repositories'
complete -c 'git remote' -s v -l verbose -d 'Be verbose'
complete -c 'git remote add' -d 'Add new remote'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions