Skip to content
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_complete: zsh completion doesn't add conflicts for group #3910

Open
2 tasks done
tmccombs opened this issue Jul 12, 2022 · 6 comments
Open
2 tasks done

clap_complete: zsh completion doesn't add conflicts for group #3910

tmccombs opened this issue Jul 12, 2022 · 6 comments
Labels
A-completion Area: completion generator C-bug Category: Updating dependencies E-easy Call for participation: Experience needed to fix: Easy / not much

Comments

@tmccombs
Copy link
Contributor

Please complete the following tasks

Rust Version

rustc 1.62.0 (a8314ef7d 2022-06-27)

Clap Version

3.2.6

Minimal reproducible code

use clap::*;
use clap_complete::{generate, shell};

fn main() {
    let mut app = Command::new("test")
        .group(ArgGroup::new("gr").args(&["a", "b"]).conflicts_with("c"))
        .arg(Arg::new("a").short('a'))
        .arg(Arg::new("b").short('b'))
        .arg(Arg::new("c").short('c'))
        .arg(&c);
    app.build();
        
   generate(shell::Zsh, &mut app, app.get_name(), &mut std::io::stdout());
}

Steps to reproduce the bug with the above code

Run code

Actual Behaviour

The zsh completions generated don't account for the conflict between the group and option c.

Expected Behaviour

The zsh completions should specify that the options in the group conflict with option c.

Additional Context

No response

Debug Output

No response

@tmccombs tmccombs added the C-bug Category: Updating dependencies label Jul 12, 2022
@epage epage added A-completion Area: completion generator E-easy Call for participation: Experience needed to fix: Easy / not much labels Jul 13, 2022
@kazuminn
Copy link

kazuminn commented May 4, 2024

Is this problem still unsolved?

@epage
Copy link
Member

epage commented May 4, 2024

With this being open, likely yes.

@kazuminn
Copy link

kazuminn commented May 5, 2024

@epage Thanks for your replay.
Could you fix this issue or tell me that how to fix this issue.
Then I can write and contribute some code of the clap_complete.
Do you have an idea of fixing?

@epage
Copy link
Member

epage commented May 6, 2024

I am not a zsh user and do not know its completion system to be able to say how to do this. I assume tmccombs verified that it supports conflicts but I'm not even sure. If it doesn't, then this is more likely to just be rejected.

We are looking at changing our completion system which would make it easier to implement these rich features and do it once for all shells. See #3166.

@tmccombs
Copy link
Contributor Author

tmccombs commented May 6, 2024

zsh does support conflicts.

You can see an example of how it is done in the fd zsh completions (which are currently manually maintained), such as here where we declare that --list-details conflicts with the abs-path, null-sep, max-results, and exec-cmds groups.

Basically, when calling _arguments you put a list of conflicting options or option groups in parenthesis before the name of the option.

From zshcompsys(1):

Each of the forms above may be preceded by a list in parentheses of option names and argument numbers. If the given option is on the command line, the options and arguments indicated in parentheses will not be offered. For example, ‘(-two -three 1)-one:...' completes the option ‘-one'; if this appears on the command line, the options -two and -three and the first ordinary argument will not be completed after it.
...
Options can be grouped to simplify exclusion lists. A group is introduced with ‘+' followed by a name for the group in the subsequent word. Whole groups can then be referenced in an exclusion list or a group name can be used to disambiguate between two forms of the same option.

@kazuminn
Copy link

kazuminn commented May 6, 2024

I have a panic with OSS hayabusa.

Yamato-Security/hayabusa#1340

thread 'main' panicked at .cargo/registry/src/index.crates.io-6f17d22bba15001f/clap_builder-4.5.2/src/builder/command.rs:3702:21:
Command::get_arg_conflicts_with: The passed arg conflicts with an arg unknown to the cmd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completion Area: completion generator C-bug Category: Updating dependencies E-easy Call for participation: Experience needed to fix: Easy / not much
Projects
None yet
Development

No branches or pull requests

3 participants