use serde::{Serialize, Deserialize};
use crate::{cli::Shell, executor::Executor};
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct Steps {
pub distro: Vec<String>,
pub steps: Vec<String>
}
impl Steps {
pub fn execute(&self, shell: &Option<Shell>) {
for step in self.steps.clone() {
let result = Executor::new(shell.clone(), step).execute();
if let Err(error) = result {
panic!("{}", error);
}
}
}
pub fn len(&self) -> usize {
self.steps.len()
}
pub fn is_empty(&self) -> bool {
self.steps.is_empty()
}
}
pub fn steps_for_dist<'a>(list: &'a Vec<Steps>, distro: &String) -> Option<&'a Steps> {
for steps in list {
for dist in steps.distro.clone() {
if dist.eq(distro) || dist == "*"{
return Some(steps)
}
}
}
None
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct InstructionSet{
execution_steps: Vec<Steps>
}
impl InstructionSet {
pub fn len(&self) -> usize {
self.execution_steps.len()
}
pub fn is_empty(&self) -> bool {
self.execution_steps.is_empty()
}
pub fn push(&mut self, step: Steps) {
self.execution_steps.push(step);
}
}