-
-
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
clap_generate: zsh broken with two multi length arguments #3022
Comments
Thanks for reporting this! One challenge with completions is we have to effectively re-implement clap's argument parsing for each shell we support. Example of other issues that look like they stem from this:
This is making me think that #1232 is even more important so we can share parsing logic between different shells and clap and more easily test it. |
To be more explicitly clear, it's not the parsing logic we need to share but rather the parsing requirements. |
The same issue arises with a more common pattern too (see https://github.com/drahnr/clap-completion-zoink/blob/84a3eb106309d066e80645f60a3065525d18c5a4 for a full working example):
On tab completion results in
|
`garden cmd <TAB>` generates an error on zsh: _arguments:comparguments:325: doubled rest argument definition: *::arguments -- Arguments to forward to custom commands: The root cause of the issue is that the generated completion script contains two `*::` entries in the `garden cmd` arguments: '*::commands -- Custom commands to run over the resolved trees:' \ '*::arguments -- Arguments to forward to custom commands:' \ A simple workaround is to drop the 2nd `*::arguments` entry. Use a `grep` filter to workaround the zsh completion bug from clap-rs/clap#3022 for now. Document the workaround and add link to the issue. Closes #10 Related-to: clap-rs/clap#3022 Signed-off-by: David Aguilar <davvid@gmail.com>
Related-to: clap-rs#3022 Signed-off-by: David Aguilar <davvid@gmail.com>
Emit the value_terminator into the zsh completion pattern when completing multi-length arguments on zsh to avoid doubled rest-arguments definitions: $ my-app <TAB> _arguments:comparguments:325: doubled rest argument definition: *::second -- second set of of multi-length arguments: Follow the suggestion from clap-rs#3266 (comment) by including the value terminator in order to resolve the ambiguity. Closes clap-rs#3022 Signed-off-by: David Aguilar <davvid@gmail.com>
I believe #4612 may resolve this issue. I ran into this while creating https://github.com/davvid/garden so I figured we might as well fix it (rather than workaround it). Kindly test it out and let me know if it works for y'all as well. |
Emit the value_terminator into the zsh completion pattern when completing multi-length arguments on zsh to avoid doubled rest-arguments definitions: $ my-app <TAB> _arguments:comparguments:325: doubled rest argument definition: *::second -- second set of of multi-length arguments: Follow the suggestion from clap-rs#3266 (comment) by including the value terminator in order to resolve the ambiguity. Closes clap-rs#3022 Signed-off-by: David Aguilar <davvid@gmail.com>
Emit the value_terminator into the zsh completion pattern when completing multi-length arguments on zsh to avoid doubled rest-arguments definitions: $ my-app <TAB> _arguments:comparguments:325: doubled rest argument definition: *::second -- second set of of multi-length arguments: Follow the suggestion from clap-rs#3266 (comment) by including the value terminator in order to resolve the ambiguity. Closes clap-rs#3022 Signed-off-by: David Aguilar <davvid@gmail.com>
Emit the value_terminator into the zsh completion pattern when completing multi-length arguments on zsh to avoid doubled rest-arguments definitions: $ my-app <TAB> _arguments:comparguments:325: doubled rest argument definition: *::second -- second set of of multi-length arguments: Follow the suggestion from clap-rs#3266 (comment) by including the value terminator in order to resolve the ambiguity. Closes clap-rs#3022 Signed-off-by: David Aguilar <davvid@gmail.com>
Expose get_value_terminator() for use by clap_complete. Related-to: clap-rs#3022 Signed-off-by: David Aguilar <davvid@gmail.com>
Emit the value_terminator into the zsh completion pattern when completing multi-length arguments on zsh to avoid doubled rest-arguments definitions: $ my-app <TAB> _arguments:comparguments:325: doubled rest argument definition: *::second -- second set of of multi-length arguments: Follow the suggestion from clap-rs#3266 (comment) by including the value terminator in order to resolve the ambiguity. Closes clap-rs#3022 Signed-off-by: David Aguilar <davvid@gmail.com>
Expose get_value_terminator() for use by clap_complete. Related-to: clap-rs#3022 Signed-off-by: David Aguilar <davvid@gmail.com>
Emit the value_terminator into the zsh completion pattern when completing multi-length arguments on zsh to avoid doubled rest-arguments definitions: $ my-app <TAB> _arguments:comparguments:325: doubled rest argument definition: *::second -- second set of of multi-length arguments: Follow the suggestion from clap-rs#3266 (comment) by including the value terminator in order to resolve the ambiguity. Closes clap-rs#3022 Signed-off-by: David Aguilar <davvid@gmail.com>
Emit the value_terminator into the zsh completion pattern when completing multi-length arguments on zsh to avoid doubled rest-arguments definitions: $ my-app <TAB> _arguments:comparguments:325: doubled rest argument definition: *::second -- second set of of multi-length arguments: Follow the suggestion from clap-rs#3266 (comment) by including the value terminator in order to resolve the ambiguity. Closes clap-rs#3022 Signed-off-by: David Aguilar <davvid@gmail.com>
Expose get_value_terminator() for use by clap_complete. Related-to: clap-rs#3022 Signed-off-by: David Aguilar <davvid@gmail.com>
Emit the value_terminator into the zsh completion pattern when completing multi-length arguments on zsh to avoid doubled rest-arguments definitions: $ my-app <TAB> _arguments:comparguments:325: doubled rest argument definition: *::second -- second set of of multi-length arguments: Follow the suggestion from clap-rs#3266 (comment) by including the value terminator in order to resolve the ambiguity. Closes clap-rs#3022 Signed-off-by: David Aguilar <davvid@gmail.com>
Emit the value_terminator into the zsh completion pattern when completing multi-length arguments on zsh to avoid doubled rest-arguments definitions: $ my-app <TAB> _arguments:comparguments:325: doubled rest argument definition: *::second -- second set of of multi-length arguments: Follow the suggestion from clap-rs#3266 (comment) by including the value terminator in order to resolve the ambiguity. Closes clap-rs#3022 Signed-off-by: David Aguilar <davvid@gmail.com>
Emit the value_terminator into the zsh completion pattern when completing multi-length arguments on zsh to avoid doubled rest-arguments definitions: $ my-app <TAB> _arguments:comparguments:325: doubled rest argument definition: *::second -- second set of of multi-length arguments: Follow the suggestion from clap-rs#3266 (comment) by including the value terminator in order to resolve the ambiguity. Closes clap-rs#3022 Signed-off-by: David Aguilar <davvid@gmail.com>
Emit the value_terminator into the zsh completion pattern when completing multi-length arguments on zsh to avoid doubled rest-arguments definitions: $ my-app <TAB> _arguments:comparguments:325: doubled rest argument definition: *::second -- second set of of multi-length arguments: Follow the suggestion from clap-rs#3266 (comment) by including the value terminator in order to resolve the ambiguity. Closes clap-rs#3022 Signed-off-by: David Aguilar <davvid@gmail.com>
Emit the value_terminator into the zsh completion pattern when completing multi-length arguments on zsh to avoid doubled rest-arguments definitions: $ my-app <TAB> _arguments:comparguments:325: doubled rest argument definition: *::second -- second set of of multi-length arguments: Follow the suggestion from clap-rs#3266 (comment) by including the value terminator in order to resolve the ambiguity. Closes clap-rs#3022 Signed-off-by: David Aguilar <davvid@gmail.com>
Emit the value_terminator into the zsh completion pattern when completing multi-length arguments on zsh to avoid doubled rest-arguments definitions: $ my-app <TAB> _arguments:comparguments:325: doubled rest argument definition: *::second -- second set of of multi-length arguments: Follow the suggestion from clap-rs#3266 (comment) by including the value terminator in order to resolve the ambiguity. Closes clap-rs#3022 Signed-off-by: David Aguilar <davvid@gmail.com>
Expose get_value_terminator() for use by clap_complete. Related-to: clap-rs#3022 Signed-off-by: David Aguilar <davvid@gmail.com>
Emit the user-defined value terminator into the zsh completion pattern to avoid doubled rest-arguments definitions: $ my-app <TAB> _arguments:comparguments:325: doubled rest argument definition: *::second -- second set of of multi-length arguments: clap-rs#3266 (comment) noted that including the value terminator is one step towards a robust solution for handling multiple multi-valued arguments. This change does not yet handle automatically detecting when a value terminator is needed, but it does add tests to ensure that user-specified value terminators are used on zsh. Related-to: clap-rs#3022 Signed-off-by: David Aguilar <davvid@gmail.com>
zsh completions for commands that end with two Vec arguments require special care to handle the transition from the penultimate multi-valued argument and the final multi-valued argument. We can have two Vec args separated with a value terminator. We can also have two Vec args with no value terminators specified. Both of these scenarios require a terminator in the zsh completions. Special-case the penultimate multi-valued argument and force it to emit a value terminator when the final argument also takes multiple values or has the `last` option set. Closes clap-rs#3022 Signed-off-by: David Aguilar <davvid@gmail.com>
zsh completions for commands that end with two Vec arguments require special care to handle the transition from the penultimate multi-valued argument and the final multi-valued argument. We can have two Vec args separated with a value terminator. We can also have two Vec args with no value terminators specified. Both of these scenarios require a terminator in the zsh completions. Special-case the penultimate multi-valued argument and force it to emit a value terminator when the final argument also takes multiple values or has the `last` option set. Closes clap-rs#3022 Signed-off-by: David Aguilar <davvid@gmail.com>
zsh completions for commands that have multiple Vec arguments require special care. We can have two Vec args separated with a value terminator. We can also have two Vec args with no value terminators specified where the final arg uses 'raw' and thus requires '--' to be used. The 2nd of these scenarios requires special handling to avoid emitting a duplicate '*:arguments' completion entry. We already use the '-S' option when calling _arguments. This option makes it so that completion stops after '--' is encountered. This means that the handling for trailing 'raw' arguments does not need to specified. Special-case multi-valued arguments so that we can skip emitting the final multi-valued argument if a previous multi-valued argument has already been emitted. Closes clap-rs#3022 Signed-off-by: David Aguilar <davvid@gmail.com>
zsh completions for commands that have multiple Vec arguments require special care. We can have two Vec args separated with a value terminator. We can also have two Vec args with no value terminators specified where the final arg uses 'raw' and thus requires '--' to be used. The 2nd of these scenarios requires special handling to avoid emitting a duplicate '*:arguments' completion entry. Currently, the zsh completions generate an error in this scenario: $ my-app <TAB> _arguments:...: doubled rest argument definition: *::second -- second set of of multi-length arguments: We already use the '-S' option when calling _arguments. This option makes it so that completion stops after '--' is encountered. This means that the handling for trailing 'raw' arguments does not need to specified. Special-case multi-valued arguments so that we can skip emitting the final multi-valued argument if a previous multi-valued argument has already been emitted. Closes clap-rs#3022 Signed-off-by: David Aguilar <davvid@gmail.com>
Have you not fully fixed this feature yet? The completion doesn't break now, but it also does nothing. Here are the Cargo.toml and the completion script: https://gist.github.com/TD-Sky/59eb28d92f8dae38129182e66da6b00c |
@TD-Sky I spent some minutes trying to compile your project and looking into what might be u. It doesn't look like the project you shared (conceal) compiles in the two branches I tried -- main and zsh-complete. If you have a working branch that that is made worse by these changes then please share the details. Feel free to take a look at how I'm setting up the subcommands but we probably shouldn't clutter this issue with too many project-specific details. Anyways, here's some working examples if you want to see them: This is the top-level parser: And this is where the sub-commands are defined: |
I have tried to compile with your patches in the local part of I have read the code your arguments parser. But you don't use |
Related-to: #10 Related-to: clap-rs/clap#3022 Related-to: clap-rs/clap#4624 Signed-off-by: David Aguilar <davvid@gmail.com>
Now that clap-rs/clap#4624 was merged we can use value_terminator to fix the zsh completions for commands that use two consecutive multi-valued arguments. A more complete solution may arrive in clap-rs/clap#4612 but until that is merged we can use this solution for now. If that change is ever merged then we can bump our clap_complete version and remove our use of value_terminator. Related-to: #10 Related-to: clap-rs/clap#3022 Related-to: clap-rs/clap#4624 Signed-off-by: David Aguilar <davvid@gmail.com>
Please complete the following tasks
Rust Version
rustc 1.58.0-nightly (8b09ba6a5 2021-11-09)
Clap Version
3.0.0-beta.5
Minimal reproducible code
Steps to reproduce the bug with the above code
With the completion installed:
Actual Behaviour
So I have a program that has a usage like this:
program: <targets>... -- <files>...
The zsh completion seems to really not like this and spits out an error when tab is hit:
_arguments:comparguments:325: doubled rest argument definition: *::file -- Files to search for:
The completion generated is:
Expected Behaviour
Don't be broken
Additional Context
No response
Debug Output
No response
The text was updated successfully, but these errors were encountered: