2022-11-10 14:54:12 +00:00
|
|
|
pub mod base;
|
2022-10-28 16:29:15 +00:00
|
|
|
pub mod common;
|
|
|
|
pub mod darwin;
|
|
|
|
pub mod linux;
|
2022-09-15 19:11:46 +00:00
|
|
|
|
2022-10-26 22:13:42 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2022-09-20 18:42:20 +00:00
|
|
|
|
2022-10-26 21:14:53 +00:00
|
|
|
#[async_trait::async_trait]
|
|
|
|
#[typetag::serde(tag = "action")]
|
2022-10-26 22:13:42 +00:00
|
|
|
pub trait Action: Send + Sync + std::fmt::Debug + dyn_clone::DynClone {
|
2022-09-27 19:05:24 +00:00
|
|
|
fn describe_execute(&self) -> Vec<ActionDescription>;
|
|
|
|
fn describe_revert(&self) -> Vec<ActionDescription>;
|
2022-09-26 21:07:53 +00:00
|
|
|
|
2022-10-28 21:15:33 +00:00
|
|
|
// They should also have an `async fn plan(args...) -> Result<ActionState<Self>, Box<dyn std::error::Error + Send + Sync>>;`
|
2022-10-26 21:14:53 +00:00
|
|
|
async fn execute(&mut self) -> Result<(), Box<dyn std::error::Error + Send + Sync>>;
|
|
|
|
async fn revert(&mut self) -> Result<(), Box<dyn std::error::Error + Send + Sync>>;
|
2022-11-08 18:18:05 +00:00
|
|
|
fn action_state(&self) -> ActionState;
|
2022-09-15 19:11:46 +00:00
|
|
|
}
|
|
|
|
|
2022-10-26 22:13:42 +00:00
|
|
|
dyn_clone::clone_trait_object!(Action);
|
2022-10-26 21:14:53 +00:00
|
|
|
|
2022-11-08 18:18:05 +00:00
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Copy)]
|
2022-09-23 23:22:50 +00:00
|
|
|
pub enum ActionState {
|
|
|
|
Completed,
|
2022-09-28 20:20:11 +00:00
|
|
|
// Only applicable to meta-actions that start multiple sub-actions.
|
|
|
|
Progress,
|
2022-09-26 23:14:25 +00:00
|
|
|
Uncompleted,
|
2022-09-15 19:11:46 +00:00
|
|
|
}
|
2022-09-14 22:18:13 +00:00
|
|
|
|
2022-09-15 17:29:22 +00:00
|
|
|
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
|
|
|
|
|
|
|
|
pub struct ActionDescription {
|
|
|
|
pub description: String,
|
|
|
|
pub explanation: Vec<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ActionDescription {
|
|
|
|
fn new(description: String, explanation: Vec<String>) -> Self {
|
2022-09-15 19:11:46 +00:00
|
|
|
Self {
|
|
|
|
description,
|
|
|
|
explanation,
|
|
|
|
}
|
2022-09-15 17:29:22 +00:00
|
|
|
}
|
|
|
|
}
|