use crate::Report;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[non_exhaustive]
pub enum Severity {
#[default]
Enforce,
Warn,
}
impl Severity {
pub fn as_str(&self) -> &'static str {
match self {
Severity::Enforce => "enforce",
Severity::Warn => "warn",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum BoundaryKind {
Crate,
Module,
Semantic,
Runtime,
}
impl BoundaryKind {
pub fn as_str(&self) -> &'static str {
match self {
BoundaryKind::Crate => "crate",
BoundaryKind::Module => "module",
BoundaryKind::Semantic => "semantic",
BoundaryKind::Runtime => "runtime",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum Polarity {
DenyBreach,
AllowlistGap,
}
impl Polarity {
pub fn as_str(&self) -> &'static str {
match self {
Polarity::DenyBreach => "deny_breach",
Polarity::AllowlistGap => "allowlist_gap",
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Outcome {
Clean,
Violations(Report),
ConstitutionError(String),
}
impl Outcome {
pub fn exit_code(&self) -> u8 {
match self {
Outcome::Clean => 0,
Outcome::Violations(report) => {
if report.violations.iter().any(|violation| {
violation.severity == Severity::Enforce && !violation.baselined
}) {
1
} else {
0
}
}
Outcome::ConstitutionError(_) => 2,
}
}
}