-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parentheses in doc comments for ValueEnum
break generated fish completions
#5101
Comments
I would like to work on this @epage. Please assign this to me. |
Below is my analysis so far: complete -c ls -l color -r -f -a "{auto do something (default)}" If I go through fish shell's documentation, I don't see any mention of adding description/hint in the complete -c ls -l color -r -f -a auto -d "do something (default)" And then try the auto-completion: $ ls --color=<TAB> I get the expected output: --color=always (Use colors) --color=auto (do something (default)) --color=never (Use colors) without any errors. I will do some more analysis with multiple parameters and their description. From the face value, it seems like separate |
I don't think it's required that we use separate
Which is what clap/clap_complete/src/shells/fish.rs Lines 171 to 175 in dc63cba
The problem is this, emphasis mine:
I tried a couple different approaches but I think the simplest solution is to wrap the description in single quotes and ditch the comma-escaping. For me, that prevents any expansion inside the description and doesn't require any complicated escaping. diff --git a/clap_complete/src/shells/fish.rs b/clap_complete/src/shells/fish.rs
index 5a069d35..175ae6aa 100644
--- a/clap_complete/src/shells/fish.rs
+++ b/clap_complete/src/shells/fish.rs
@@ -169,9 +169,9 @@ fn value_completion(option: &Arg) -> String {
None
} else {
Some(format!(
- "{}\t{}",
+ "{}\t'{}'",
escape_string(value.get_name(), true).as_str(),
- escape_string(&value.get_help().unwrap_or_default().to_string(), true)
+ escape_string(&value.get_help().unwrap_or_default().to_string(), false)
))
})
.collect::<Vec<_>>() |
Valid point @cstyles. I tried few more variations with your solution. Here are my observations: $ complete -c ls -l color -r -f -a "{auto\t'do something (default)',never\t'no color',always\t'always color'}"
$ ls --color=<TAB>
--color=always (always color) --color=auto (do something (default)) --color=never (no color) ✕ - I believe this is expected, so this case is fine? $ complete -c ls -l color -r -f -a "{auto\t'do something %$# (default)',never\t'no &* color',always\t'always!! color'}"
$ ls --color=<TAB>
fish: $# is not supported. In fish, please use 'count $argv'.
complete -c ls -l color -r -f -a "{auto\t'do something %$# (default)',never\t'no &* color',always\t'always!! color'}" ✕ - Same as the previous one. $ complete -c ls -l color -r -f -a "{auto\t'do something %$ (default)',never\t'no &* color',always\t'always!! color'}"
$ ls --color=<TAB>
fish: $ is not a valid variable in fish.
complete -c ls -l color -r -f -a "{auto\t'do something %$ (default)',never\t'no &* color',always\t'always!! color'}" ✓ $ complete -c ls -l color -r -f -a "{auto\t'do something % (default)',never\t'no &* color',always\t'always!! color'}"
$ ls --color=<TAB>
--color=always (always!! color) --color=auto (do something % (default)) --color=never (no &* color) So, in summary, the solution to enclose the help text in |
Resolves clap-rs#5101 - The completion of value enums now displays accurate help text - This fix encloses help text in single quotes - Comma in help text is not escaped - This is because the the help text is now treated as literal - No variable expansion or command substitution in help text
Resolves clap-rs#5101 - The completion of value enums now displays accurate help text - This fix encloses help text in single quotes - Comma in help text is not escaped - This is because the the help text is now treated as literal - No variable expansion or command substitution in help text
Resolves clap-rs#5101 - The completion of value enums now displays accurate help text - This fix encloses help text in single quotes - Comma in help text is not escaped - This is because the the help text is now treated as literal - No variable expansion or command substitution in help text
Resolves clap-rs#5101 - The completion of value enums now displays accurate help text - This fix encloses help text in single quotes - Any text after tab is taken as help text - Comma in help text is not escaped - This is because the the help text is now treated as literal - No variable expansion or command substitution in help text
Please complete the following tasks
Rust Version
rustc 1.72.0 (5680fa18f 2023-08-23)
Clap Version
4.4.1
Minimal reproducible code
Steps to reproduce the bug with the above code
Actual Behaviour
Expected Behaviour
Additional Context
The solution might just be to escape parentheses in
clap_complete::shells::Fish::escape_string
. But A) I'm not sure if there are unintended consequences of doing that and B) the docs for that function mention that it's for escaping single quoted strings which the completions don't use. But it's also used invalue_completion
to escape a string inside double quotes so maybe that comment is just out-of-date? I didn't feel confident making the change so I'll defer to someone more knowledgeable.Debug Output
No response
The text was updated successfully, but these errors were encountered: