use anyhow::Ok;
use strum::IntoEnumIterator;
use tracel_xtask_utils::{
cargo::ensure_cargo_crate_is_installed, endgroup, environment::Environment, group,
process::run_process,
};
use crate::context::Context;
#[tracel_xtask_macros::declare_command_args(None, DependenciesSubCommand)]
pub struct DependenciesCmdArgs {}
pub fn handle_command(
args: DependenciesCmdArgs,
_env: Environment,
_ctx: Context,
) -> anyhow::Result<()> {
match args.get_command() {
DependenciesSubCommand::Deny => run_cargo_deny(),
DependenciesSubCommand::Unused => run_cargo_machete(),
DependenciesSubCommand::All => DependenciesSubCommand::iter()
.filter(|c| *c != DependenciesSubCommand::All)
.try_for_each(|c| {
handle_command(
DependenciesCmdArgs { command: Some(c) },
_env.clone(),
_ctx.clone(),
)
}),
}
}
fn run_cargo_deny() -> anyhow::Result<()> {
ensure_cargo_crate_is_installed("cargo-deny", None, None, false)?;
group!("Cargo: run deny checks");
run_process(
"cargo",
&["deny", "check"],
None,
None,
"Some dependencies don't meet the requirements!",
)?;
endgroup!();
Ok(())
}
fn run_cargo_machete() -> anyhow::Result<()> {
ensure_cargo_crate_is_installed("cargo-machete", None, None, false)?;
group!("Cargo: run unused dependencies checks");
run_process(
"cargo",
&["machete"],
None,
None,
"Unused dependencies found!",
)?;
endgroup!();
Ok(())
}