use crate::terminal::{Color, Terminal, Verbosity};
use clap::{ArgAction, Args};
#[derive(Args)]
#[command(
after_help = "Unrecognized subcommands will be passed to cargo verbatim after relevant component bindings are updated."
)]
pub struct CommonOptions {
#[clap(long = "quiet", short = 'q')]
pub quiet: bool,
#[clap(
long = "verbose",
short = 'v',
action = ArgAction::Count
)]
pub verbose: u8,
#[clap(long = "color", value_name = "WHEN")]
pub color: Option<Color>,
}
impl CommonOptions {
pub fn new_terminal(&self) -> Terminal {
Terminal::new(
if self.quiet {
Verbosity::Quiet
} else {
match self.verbose {
0 => Verbosity::Normal,
_ => Verbosity::Verbose,
}
},
self.color.unwrap_or_default(),
)
}
}