expression

Clap counted verbosity flags

A counting flag records how many times it occurs, such as -vv for two levels. Convert the count into a documented verbosity policy; avoid logging secrets at any level. Uses a fixed synthetic argument list or local data. Expected stdout (not executed): verbosity: 2 Common mistake: Treating a verbosity count as permission to expose credentials.

Formal Syntax & Structure

rust syntaxrust
#[arg(short, action = clap::ArgAction::Count)] verbose: u8

Working Example

Example Snippetrust
fn main() {    use clap::Parser;    #[derive(Parser)]    struct Cli { #[arg(short, action = clap::ArgAction::Count)] verbose: u8 }    let cli = Cli::try_parse_from(["report", "-vv"]).unwrap();    println!("verbosity: {}", cli.verbose);}
Rust Reference