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

Don't show flags in native completion that are already present #5515

Open
2 tasks done
HKalbasi opened this issue Jun 1, 2024 · 1 comment
Open
2 tasks done

Don't show flags in native completion that are already present #5515

HKalbasi opened this issue Jun 1, 2024 · 1 comment
Labels
A-completion Area: completion generator C-bug Category: Updating dependencies E-easy Call for participation: Experience needed to fix: Easy / not much

Comments

@HKalbasi
Copy link

HKalbasi commented Jun 1, 2024

Please complete the following tasks

Rust Version

1.76

Clap Version

4.5.2

Minimal reproducible code

use clap::{CommandFactory, Parser, ValueEnum};

#[derive(Debug, Parser)]
#[command(version, about, long_about = None)]
struct Cli {
    /// What mode to run the program in
    #[arg(short, long, value_enum)]
    mode: Mode,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
enum Mode {
    /// Run swiftly
    Fast,
    /// Crawl slowly but steadily
    ///
    /// This paragraph is ignored because there is no long help text for possible values.
    Slow,
}
fn main() {
    let mut cmd = Cli::command();
    let args = std::env::args_os().collect::<Vec<_>>();
    let arg_index = args.len() - 1;
    let r = clap_complete::dynamic::complete(&mut cmd, args, arg_index, None).unwrap();
    dbg!(r);
}}

Steps to reproduce the bug with the above code

cargo run -- --mode fast --mo

Actual Behaviour

[src/main.rs:25:5] r = [
    (
        "--mode",
        Some(
            StyledStr(
                "What mode to run the program in",
            ),
        ),
    ),
]

Expected Behaviour

[src/main.rs:25:5] r = []

Additional Context

Using --mode is invalid, so we should not complete it. Obviously flags that accept multiple values should keep the existing behavior.

Debug Output

No response

@HKalbasi HKalbasi added the C-bug Category: Updating dependencies label Jun 1, 2024
@epage epage added A-completion Area: completion generator E-easy Call for participation: Experience needed to fix: Easy / not much labels Jun 2, 2024
@epage
Copy link
Member

epage commented Jun 2, 2024

There is a little more to it. We should only do this if the ArgAction prevenhs it and if we don't override ourself.

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

2 participants