1mod cargo_deny;
2mod commitalyzer;
3mod github_workflows;
4mod licenses;
5pub mod pre_commit;
6mod semver_release;
7mod vhooks;
8
9use std::path::Path;
10
11pub use cargo_deny::CargoDeny;
12pub use commitalyzer::{Commitalyzer, Ruleset};
13pub use github_workflows::{GithubWorkflows, Parameters, Workflow};
14pub use licenses::{LICENSES_DIR, Licenses};
15pub use pre_commit::PreCommit;
16pub use semver_release::{
17 Plugin, RELEASE_BIN_NAME, RELEASE_CONFIG_NAME, RELEASE_DIR_NAME, SemverRelease,
18};
19pub use vhooks::Vhooks;
20
21use crate::SolarError;
22
23use clap::Subcommand as SC;
24
25pub enum Action {
26 INSTALL,
27 UPGRADE,
28 UNINSTALL,
29}
30
31pub trait ToolTrait {
32 fn act(&mut self, action: &Action, dest: Option<&Path>) -> Result<(), SolarError> {
33 if let Some(wd) = dest {
34 self.set_dest(wd);
35 }
36 match action {
37 Action::INSTALL => self.install(),
38 Action::UPGRADE => self.upgrade(),
39 Action::UNINSTALL => self.uninstall(),
40 }
41 }
42
43 fn set_dest(&mut self, dest: &Path);
44
45 fn install(&mut self) -> Result<(), SolarError>;
46
47 fn uninstall(&mut self) -> Result<(), SolarError>;
48
49 fn upgrade(&mut self) -> Result<(), SolarError> {
50 println!("Nothing to upgrade for this tool.");
51 Ok(())
52 }
53}
54
55#[derive(SC, Clone, PartialEq, Debug)]
56pub enum Tool {
57 VHOOKS(Vhooks),
59
60 COMMITALYZER(Commitalyzer),
62
63 SEMVERRELEASE(SemverRelease),
65
66 LICENSES(Licenses),
68
69 WORKFLOWS(GithubWorkflows),
71
72 PRECOMMIT(PreCommit),
74
75 DENY(CargoDeny),
77}
78
79impl Tool {
80 pub fn act(&mut self, action: &Action, dest: Option<&Path>) -> Result<(), SolarError> {
81 match self {
82 Self::VHOOKS(tool) => tool.act(action, dest),
83 Self::COMMITALYZER(tool) => tool.act(action, dest),
84 Self::SEMVERRELEASE(tool) => tool.act(action, dest),
85 Self::LICENSES(tool) => tool.act(action, dest),
86 Self::WORKFLOWS(tool) => tool.act(action, dest),
87 Self::PRECOMMIT(tool) => tool.act(action, dest),
88 Self::DENY(tool) => tool.act(action, dest),
89 }
90 }
91}