use clap::{Args, ValueEnum};
#[derive(Args)]
pub struct ToolsArgs {
#[arg(short = 'a', long, conflicts_with = "install")]
all: bool,
#[arg(short = 'u', long)]
upgrade: bool,
#[arg(long, value_delimiter = ',', value_enum, conflicts_with = "all")]
install: Option<Vec<ToolName>>,
#[arg(short = 'y', long)]
yolo: bool,
#[arg(short = 'v', long)]
verbose: bool,
}
impl ToolsArgs {
pub fn run(self) -> anyhow::Result<()> {
cargo_gears_core::tools::ToolsParams::from(self).run()
}
}
impl From<ToolsArgs> for cargo_gears_core::tools::ToolsParams {
fn from(args: ToolsArgs) -> Self {
Self {
all: args.all,
upgrade: args.upgrade,
install: args
.install
.map(|tools| tools.into_iter().map(Into::into).collect()),
yolo: args.yolo,
verbose: args.verbose,
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, ValueEnum)]
enum ToolName {
Rustup,
Rustfmt,
Clippy,
}
impl From<ToolName> for cargo_gears_core::tools::ToolName {
fn from(tool: ToolName) -> Self {
match tool {
ToolName::Rustup => Self::Rustup,
ToolName::Rustfmt => Self::Rustfmt,
ToolName::Clippy => Self::Clippy,
}
}
}