Skip to main content

cfgd_core/output/
verbosity.rs

1use std::path::PathBuf;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub enum Verbosity {
5    Quiet,
6    Normal,
7    Verbose,
8}
9
10#[derive(Debug, Clone, PartialEq, Eq)]
11pub enum OutputFormat {
12    Table,
13    Wide,
14    Json,
15    Yaml,
16    Name,
17    Jsonpath(String),
18    Template(String),
19    TemplateFile(PathBuf),
20}
21
22impl OutputFormat {
23    /// True when the format expects machine-consumable structured output.
24    /// Used to auto-quiet status output and to refuse interactive prompts.
25    pub fn is_structured(&self) -> bool {
26        !matches!(self, OutputFormat::Table | OutputFormat::Wide)
27    }
28}
29
30#[cfg(test)]
31mod tests {
32    use super::*;
33
34    #[test]
35    fn structured_modes_classified() {
36        assert!(!OutputFormat::Table.is_structured());
37        assert!(!OutputFormat::Wide.is_structured());
38        assert!(OutputFormat::Json.is_structured());
39        assert!(OutputFormat::Yaml.is_structured());
40        assert!(OutputFormat::Name.is_structured());
41        assert!(OutputFormat::Jsonpath("{.foo}".into()).is_structured());
42    }
43}