use crate::diag::{Diagnostic, SgCode};
pub fn service_not_found(service: &str) -> Diagnostic {
Diagnostic::error(
SgCode::TargetNotFound,
format!("no service named `{service}` to inspect"),
)
.note("inspect details one running or configured service; check the name")
.help_cmd("list services", "sysg status")
.help_docs()
}
pub fn invalid_stream_duration(value: &str, reason: impl Into<String>) -> Diagnostic {
Diagnostic::error(
SgCode::Catchall,
format!("`--stream` value `{value}` is not a valid duration"),
)
.note(reason)
.help_cmd("use seconds or a unit", "sysg inspect -s web --stream 5")
.help_docs()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn service_not_found_is_sg0202() {
let diag = service_not_found("web");
assert_eq!(diag.code, SgCode::TargetNotFound);
assert!(diag.render(false).contains("web"));
}
#[test]
fn invalid_stream_duration_names_the_value() {
let diag = invalid_stream_duration("xyz", "not a number");
assert!(diag.render(false).contains("xyz"));
}
}