Skip to content

allow_external_subcommands interacts weirdly with boolean flags? #5812

Answered by epage
senekor asked this question in Q&A
Discussion options

You must be logged in to vote

The issue is more with ignore_errors which has a lot of unspecified behavior

#!/usr/bin/env nargo
---
[dependencies]
clap = { version = "4", features = ["derive"] }
---

use clap::{Command, Arg, builder::ArgAction};

fn app() -> clap::Command {
    Command::new("foo")
        .arg(Arg::new("bool_flag").long("bool-flag").action(ArgAction::SetTrue))
        //.ignore_errors(true)
}

fn parse(app: clap::Command, args: &[&str], case: &str) {
    match app.try_get_matches_from(args) {
        Ok(m) => {
            println!("{case}: {:?}", m.get_one::<bool>("bool_flag"));
        },
        Err(err) => {
            println!("{case}");
            let _ = err.print();
        },
    }
}

fn main(

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@epage
Comment options

Answer selected by senekor
@senekor
Comment options

@epage
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants