Skip to content

Commit

Permalink
Add prefix implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
isbm committed Oct 22, 2024
1 parent ad2b3ad commit b3953ae
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions libsysinspect/src/reactor/handlers/cstr_stdhdl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ pub struct ConstraintHandler {
config: EventConfig,
}

impl ConstraintHandler {
/// Get prefix from the configuration
fn get_prefix(&self) -> String {
let mut prefix = "".to_string();
if let Some(config) = self.config() {
if let Some(p) = config.as_string("prefix") {
prefix = format!("{} - ", p.cyan());
}
}

prefix
}
}

/// STDOUT event handler. It just outputs the action response to a log.
impl EventHandler for ConstraintHandler {
fn new(eid: String, cfg: EventConfig) -> Self
Expand All @@ -36,14 +50,16 @@ impl EventHandler for ConstraintHandler {
return;
}

let prefix = self.get_prefix();

if !evt.errors.has_errors() {
log::info!("All constraints {}", "passed".bright_green().bold());
log::info!("{}All constraints {}", prefix, "passed".bright_green().bold());
return;
}

log::info!("{}", evt.errors.descr());
for f in evt.errors.failures() {
log::error!("{}: {}", f.title.yellow(), f.msg);
log::error!("{}{}: {}", prefix, f.title.yellow(), f.msg);
}
}

Expand Down

0 comments on commit b3953ae

Please sign in to comment.