-
Hello everybody! I'm starting to learn using the I started with some simple arguments, and for some (unknown?) reason I used #[cfg(test)]
mod tests {
use clap::builder::Styles;
use clap::Parser;
#[derive(Parser, Debug)]
#[command(styles = Styles::plain())]
struct Args {
#[arg(long, value_name = "BOOL", help = "First option")]
first: Option<bool>,
#[arg(
long,
value_name = "BOOL",
default_value_t = true,
help = "Second option"
)]
second: bool,
}
#[test]
fn test_help_text() {
let error = Args::try_parse_from(["app", "--help"]).err().unwrap();
let help_text = [
"Usage: app [OPTIONS]",
"",
"Options:",
" --first <BOOL> First option [possible values: true, false]",
" --second Second option",
" -h, --help Print help",
"",
]
.join("\n");
assert_eq!(format!("{error}"), help_text);
}
} When using I wonder, is this the expected output? Do I have a chance to tweak it? Using the Many thanks in advance, rustc version 1.80.1 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Stupid me, I completely missed the fact that |
Beta Was this translation helpful? Give feedback.
Stupid me, I completely missed the fact that
bool
is treated as flag by default. Usingaction = ArgAction::Set
seems to work as expected.