gw_bin/actions/
mod.rs

1use crate::context::Context;
2use mockall::automock;
3use thiserror::Error;
4
5/// An action to run in the background and restart a subprocess.
6pub mod process;
7/// An action to run a custom shell script.
8pub mod script;
9/// Utilities for shared code
10pub mod utils;
11
12/// A custom error for describing the error cases for actions
13#[derive(Debug, Error)]
14pub enum ActionError {
15    /// Cannot initialize action, because it has a misconfiguration.
16    #[error("not configured correctly: {0}")]
17    Misconfigured(String),
18    /// Cannot run action, because there isn't enough permission.
19    #[error("permission denied: {0}")]
20    PermissionDenied(String),
21    /// Running action failed. It is usually a runtime issue.
22    #[error("{0}")]
23    FailedAction(String),
24}
25
26/// An action is a process that runs if any changes occured.
27///
28/// Actions may include:
29///   - running scripts ([script::ScriptAction])
30///   - etc.
31#[automock]
32pub trait Action {
33    /// Initiate the action
34    fn run(&mut self, context: &Context) -> Result<(), ActionError>;
35}