use super::model::{Criterion, RuleKind};
#[derive(Debug, Clone)]
pub struct RuleItem {
pub description: String,
pub kind: Option<RuleKind>,
pub args: Vec<String>,
}
impl RuleItem {
pub fn machine(&self) -> bool {
self.kind.is_some()
}
}
pub fn items_of(criteria: &[Criterion]) -> Vec<RuleItem> {
criteria
.iter()
.map(|criterion| {
let description = criterion.text();
let (kind, args) = match criterion {
Criterion::PathExists { path, .. } => {
(Some(RuleKind::PathExists), vec![path.clone()])
}
Criterion::PathAbsent { absent, .. } => {
(Some(RuleKind::PathAbsent), vec![absent.clone()])
}
Criterion::FileContains { file, contains, .. } => (
Some(RuleKind::FileContains),
vec![file.clone(), contains.clone()],
),
Criterion::CommandRun { run, .. } => {
(Some(RuleKind::CommandRun), vec![run.clone()])
}
Criterion::AgentJudgement { .. } | Criterion::HumanGate { .. } => {
(None, Vec::new())
}
};
RuleItem {
description,
kind,
args,
}
})
.collect()
}