1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use mockall::automock;
use thiserror::Error;

/// An action to run a custom shell script.
pub mod script;

/// A custom error for describing the error cases for actions
#[derive(Debug, Error)]
pub enum ActionError {
    /// Cannot initialize action, because it has a misconfiguration.
    #[error("not configured correctly: {0}")]
    Misconfigured(String),
    /// Cannot run action, because there isn't enough permission.
    #[error("permission denied: {0}")]
    PermissionDenied(String),
    /// Running action failed. It is usually a runtime issue.
    #[error("{0}")]
    FailedAction(String),
}

/// An action is a process that runs if any changes occured.
///
/// Actions may include:
///   - running scripts ([script::ScriptAction])
///   - etc.
#[automock]
pub trait Action {
    /// Initiate the action
    fn run(&self) -> Result<(), ActionError>;
}