use std::path::PathBuf;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "kebab-case")]
pub enum FlowPhase {
#[default]
Prepare,
Download,
Extract,
Verify,
Register,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(tag = "log", rename_all = "kebab-case")]
#[non_exhaustive]
pub enum FlowLog {
FileWrite { path: PathBuf },
FileReuse { path: PathBuf },
ScriptBegin { name: String },
ScriptLine { name: String, line: String },
CommandDone { command: String },
Warning { code: String, detail: String },
}
impl FlowLog {
pub fn is_script(&self) -> bool {
matches!(
self,
FlowLog::ScriptBegin { .. } | FlowLog::ScriptLine { .. } | FlowLog::CommandDone { .. }
)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(tag = "event", rename_all = "kebab-case")]
#[non_exhaustive]
pub enum FlowEvent {
Started,
Progress {
phase: FlowPhase,
step: String,
percent: Option<u8>,
},
Log { record: FlowLog },
Completed,
Failed {
message: String,
},
}
pub trait Flow {
fn run(&self, on_event: &mut dyn FnMut(FlowEvent)) -> Result<(), crate::error::ShunError>;
}