1mod cargo_deny;
2mod commitalyzer;
3mod github_workspaces;
4mod licenses;
5mod pre_commit;
6mod semver_release;
7mod vhooks;
8
9pub use cargo_deny::CargoDeny;
10pub use commitalyzer::Commitalyzer;
11pub use github_workspaces::Workspaces;
12pub use licenses::Licenses;
13pub use pre_commit::PreCommit;
14pub use semver_release::SemverRelease;
15pub use vhooks::Vhooks;
16
17use crate::SolarError;
18
19use strum::IntoEnumIterator;
20use strum_macros::EnumIter;
21
22use clap::Subcommand as SC;
23
24pub enum Action {
25 INSTALL,
26 UPGRADE,
27 REMOVE,
28}
29
30pub trait ToolTrait {
31 fn act(&self, action: &Action) -> Result<(), SolarError> {
32 match action {
33 Action::INSTALL => self.install(),
34 Action::UPGRADE => self.upgrade(),
35 Action::REMOVE => self.remove(),
36 }
37 }
38
39 fn install(&self) -> Result<(), SolarError>;
40
41 fn remove(&self) -> Result<(), SolarError>;
42
43 fn upgrade(&self) -> Result<(), SolarError> {
44 self.remove()?;
45 self.install()?;
46 Ok(())
47 }
48}
49
50#[derive(SC, Clone, EnumIter, PartialEq, Debug)]
51pub enum Tool {
52 VHOOKS(Vhooks),
54
55 COMMITALYZER(Commitalyzer),
57
58 SEMVERRELEASE(SemverRelease),
60
61 LICENSES(Licenses),
63
64 WORKSPACES(Workspaces),
66
67 PRECOMMIT(PreCommit),
69
70 DENY(CargoDeny),
72}
73
74impl Tool {
75 fn act(&self, action: &Action) -> Result<(), SolarError> {
76 match self {
77 Self::VHOOKS(tool) => tool.act(action),
78 Self::COMMITALYZER(tool) => tool.act(action),
79 Self::SEMVERRELEASE(tool) => tool.act(action),
80 Self::LICENSES(tool) => tool.act(action),
81 Self::WORKSPACES(tool) => tool.act(action),
82 Self::PRECOMMIT(tool) => tool.act(action),
83 Self::DENY(tool) => tool.act(action),
84 }
85 }
86
87 pub fn perform(arg: &Option<Self>, action: Action) -> Result<(), SolarError> {
88 match arg {
89 Some(tool) => tool.act(&action),
90 None => {
91 for tool in Self::iter() {
92 tool.act(&action)?;
93 }
94 Ok(())
95 }
96 }
97 }
98}