cargo_component_core/
command.rsuse std::path::PathBuf;
use clap::{ArgAction, Args};
use crate::terminal::{Color, Terminal, Verbosity};
pub const CACHE_DIR_ENV_VAR: &str = "CARGO_COMPONENT_CACHE_DIR";
pub const CONFIG_FILE_ENV_VAR: &str = "CARGO_COMPONENT_CONFIG_FILE";
#[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>,
#[clap(long = "cache-dir", env = CACHE_DIR_ENV_VAR)]
pub cache_dir: Option<PathBuf>,
#[clap(long = "config", env = CONFIG_FILE_ENV_VAR)]
pub config: Option<PathBuf>,
}
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(),
)
}
}