mod cargo_deny;
mod commitalyzer;
mod github_workspaces;
mod licenses;
mod pre_commit;
mod semver_release;
mod vhooks;
pub use cargo_deny::CargoDeny;
pub use commitalyzer::Commitalyzer;
pub use github_workspaces::Workspaces;
pub use licenses::Licenses;
pub use pre_commit::PreCommit;
pub use semver_release::SemverRelease;
pub use vhooks::Vhooks;
use crate::SolarError;
use strum::IntoEnumIterator;
use strum_macros::EnumIter;
use clap::Subcommand as SC;
pub enum Action {
INSTALL,
UPGRADE,
REMOVE,
}
pub trait ToolTrait {
fn act(&self, action: &Action) -> Result<(), SolarError> {
match action {
Action::INSTALL => self.install(),
Action::UPGRADE => self.upgrade(),
Action::REMOVE => self.remove(),
}
}
fn install(&self) -> Result<(), SolarError>;
fn remove(&self) -> Result<(), SolarError>;
fn upgrade(&self) -> Result<(), SolarError> {
self.remove()?;
self.install()?;
Ok(())
}
}
#[derive(SC, Clone, EnumIter, PartialEq, Debug)]
pub enum Tool {
VHOOKS(Vhooks),
COMMITALYZER(Commitalyzer),
SEMVERRELEASE(SemverRelease),
LICENSES(Licenses),
WORKSPACES(Workspaces),
PRECOMMIT(PreCommit),
DENY(CargoDeny),
}
impl Tool {
fn act(&self, action: &Action) -> Result<(), SolarError> {
match self {
Self::VHOOKS(tool) => tool.act(action),
Self::COMMITALYZER(tool) => tool.act(action),
Self::SEMVERRELEASE(tool) => tool.act(action),
Self::LICENSES(tool) => tool.act(action),
Self::WORKSPACES(tool) => tool.act(action),
Self::PRECOMMIT(tool) => tool.act(action),
Self::DENY(tool) => tool.act(action),
}
}
pub fn perform(arg: &Option<Self>, action: Action) -> Result<(), SolarError> {
match arg {
Some(tool) => tool.act(&action),
None => {
for tool in Self::iter() {
tool.act(&action)?;
}
Ok(())
}
}
}
}