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 dynamic doesn't work with ValueEnum in args #5498

Closed
2 tasks done
HKalbasi opened this issue May 22, 2024 · 1 comment
Closed
2 tasks done

Clap complete dynamic doesn't work with ValueEnum in args #5498

HKalbasi opened this issue May 22, 2024 · 1 comment
Labels
C-bug Category: bug

Comments

@HKalbasi
Copy link
Contributor

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 fa

Actual Behaviour

The output is:

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

Expected Behaviour

The output should be:

[src/main.rs:25:5] r = [
    (
        "fast",
        Some(
            StyledStr(
                "Run swiftly",
            ),
        ),
    ),
]

Additional Context

No response

Debug Output

[clap_builder::builder::command]Command::_build: name="clap-test"
[clap_builder::builder::command]Command::_propagate:clap-test
[clap_builder::builder::command]Command::_check_help_and_version:clap-test expand_help_tree=true
[clap_builder::builder::command]Command::long_help_exists
[clap_builder::builder::command]Command::_check_help_and_version: Building default --help
[clap_builder::builder::command]Command::_check_help_and_version: Building default --version
[clap_builder::builder::command]Command::_propagate_global_args:clap-test
[clap_builder::builder::debug_asserts]Command::_debug_asserts
[clap_builder::builder::debug_asserts]Arg::_debug_asserts:mode
[clap_builder::builder::debug_asserts]Arg::_debug_asserts:help
[clap_builder::builder::debug_asserts]Arg::_debug_asserts:version
[clap_builder::builder::debug_asserts]Command::_verify_positionals
[clap_builder::builder::command]Command::_build_bin_names
[ clap_builder::output::usage]Usage::get_required_usage_from: incls=[], matcher=false, incl_last=true
[ clap_builder::output::usage]Usage::get_required_usage_from: unrolled_reqs=["mode"]
[ clap_builder::output::usage]Usage::get_required_usage_from:iter:"mode" arg is_present=false
[ clap_builder::output::usage]Usage::get_required_usage_from: ret_val=[StyledStr("\u{1b}[1m--mode\u{1b}[0m <MODE>")]
[clap_complete::dynamic::completer]     complete::next: Begin parsing '"--mode"'
[clap_complete::dynamic::completer]     complete_arg: arg=ParsedArg { inner: "fa" }, cmd="clap-test", current_dir=None, pos_index=1, is_escaped=false
[clap_complete::dynamic::completer]     complete_subcommand: cmd="clap-test", value="fa"
[clap_complete::dynamic::completer]     subcommands: name=clap-test
[clap_complete::dynamic::completer]     subcommands: Has subcommands...false
@HKalbasi HKalbasi added the C-bug Category: bug label May 22, 2024
@HKalbasi
Copy link
Contributor Author

Ah, this is duplicate of #3920, sorry for noise.

@HKalbasi HKalbasi closed this as not planned Won't fix, can't repro, duplicate, stale May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

1 participant