fish/complete: Generate helper functions to check for subcommands #5568
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As guided by fish's maintainer, to handle nested subcommands, we try to generate 3 new functions for completion scripts:
__fish_{name}_global_optspecs
will gather global option specifications,__fish_{name}_needs_command
, withrustup \t
, used to check forrustup
__fish_{name}_using_subcommand show
, withrustup show \t
, check if current cmd isshow
This pattern is popular within fish-shell repository, for some commands:
This is complicated, as stated by fish's maintainers. Let's hope the new fish proposal will improve things.
This PR contains a HACK: Assuming subcommands are only nested less than 3 levels as more than that is unwieldy and takes more effort to support. For example,
rustup toolchain help install
is the longest valid command line ofrustup
that uses nested subcommands, and it cannot receive any flags to it.