feat(complete): group options by tag (in zsh)#6334
feat(complete): group options by tag (in zsh)#6334bobrippling wants to merge 3 commits intoclap-rs:masterfrom
zsh)#6334Conversation
e5a4b4d to
629cac1
Compare
zsh)zsh)
a419619 to
65f0b45
Compare
This allows us to label an option as `global`, for testing Also register `dynamic` as a test example
65f0b45 to
b161c88
Compare
| /// Group candidates based on if they are global | ||
| /// | ||
| /// Future: these may become user-visible | ||
| pub fn global(mut self, global: bool) -> Self { |
There was a problem hiding this comment.
This is separate from the rest of this PR and should be split out. Likely we should even discuss it in an issue first, per our contrib guide
There was a problem hiding this comment.
Sure, I've split out the global change. I've created a new issue to discuss it - #6343.
My goal with the current issue was to split global and non-global options, let me know if you'd like me to tweak it so it's more clear it's about tagging
There was a problem hiding this comment.
Thanks for the review and feedback btw - I'm currently not home but I'll be able to get round to making changes soon
b161c88 to
0609ae5
Compare
zsh)zsh)
| #[cfg(feature = "unstable-shell-tests")] | ||
| fn register_dynamic_env() { | ||
| common::register_example::<RuntimeBuilder>("dynamic-env", "exhaustive"); | ||
| common::register_example::<RuntimeBuilder>("dynamic-env", "dynamic"); |
There was a problem hiding this comment.
The tests are testing using exhaustive which already has a global(true) on it.
Is this unused? Do we then need to add the global arg?
| if [[ "$value" == */ ]]; then | ||
| local dir_no_slash="${value%/}" | ||
| if [[ "$completion" == *:* ]]; then | ||
| local desc="${completion#*:}" | ||
| if [[ "$value" == *:* ]]; then | ||
| local desc="${value#*:}" | ||
| dirs+=("$dir_no_slash:$desc") | ||
| else | ||
| dirs+=("$dir_no_slash") | ||
| fi | ||
| else | ||
| other+=("$completion") | ||
| if (( ${+tag_map["$tag"]} )); then # key exists? | ||
| tag_map["$tag"]+=$'\n'"$value" | ||
| else | ||
| tag_map["$tag"]="$value" | ||
| fi | ||
| fi |
There was a problem hiding this comment.
Does this mean we aren't getting the / handling if a tag is present?
| } | ||
| write!( | ||
| buf, | ||
| "{}:", |
There was a problem hiding this comment.
No test output changed in this commit. Are the commits not atomic or are they not covering the right behavior?
This allows zsh to group completions by whether they're global, and then by their tag. For example:
Closes #6320
Outstanding Questions
Options name
completing "Options" optionsdoesn't seem particulary nice, should we filter out the default"Options"tag?clap/clap_complete/src/engine/complete.rs
Lines 532 to 534 in 1420275
when generating the completions in
shells.rsTests
My new test is currently failing because it gets the zsh initial login setup:
I'm not sure why my test gets this but the others don't