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'
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_subcommandand__fish_cmdname_using_subcommandand then use them as conditions like so:This leads to a lot of duplicated code and could be buggy. Adding a
--subcommandflag to thecompletecommand to specify subcommands and options exclusive to them could be very useful. Something like this:Or maybe the
-cflag itself can take care of the subcommands, which IMO is more readable and intuitive, especially in the case for subcommands of subcommands: