[clap_complete/dyamic] subcommands per shell for complete/generate and restructure #5157
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.
This is to make progress for #1232.
It's hard to understand how each shell works. They all have their own environment variables and more. To make it all easier to understand and not one big file, I moved shell specific implementations into 2 separate parts/subcommands and into separate files:
This makes the autocomplete example's
--help
look like this as well:Where the
complete
andgenerate
subcommands now have a subcommand for each shell:For Bash the generation does not have any CLI arguments but has the following changes:
complete
options (-o
) set tonosort
,noquote
, andnospace
fromnospace
, andbashdefault
. Meaning the results are not sorted nor quoted are appended with a space. This should make it easier to make all shells act the same.The completion part's arguments are those that were previously passed via environment variables, making it easier to use.
Some refactoring as well and the structure of the dynamic folder looks like this:
complete bash
subcommand struct and implementationgenerate bash
subcommand struct and implementationcomplete
andgenerate
command struct and implementation.Completer
struct.Completer
was renamed toRegistrar
because it did both generation and completion which made it actually hard to follow what data is used where. Still somewhat unsure whether to keep it or not, but for now I've chosen to keep it because this PR is already too big.Some of the next steps for future PRs: