Skip to main content

entrenar_common/
lib.rs

1//! Shared infrastructure for entrenar CLI tools.
2//!
3//! This crate provides common utilities used across all entrenar sub-crates:
4//! - CLI styling and output formatting
5//! - Error handling with actionable diagnostics
6//! - Table rendering for terminal output
7//! - Progress indicators
8//!
9//! # Toyota Way Principles
10//!
11//! - **Jidoka**: Rich error messages with actionable diagnostics
12//! - **Andon**: Visual problem indication through consistent styling
13//! - **Muda Elimination**: Single source of truth for shared code
14
15pub mod cli;
16pub mod error;
17pub mod output;
18pub mod progress;
19
20pub use cli::{Cli, OutputFormat};
21pub use error::{EntrenarError, Result};
22pub use output::{Table, TableBuilder};
23
24/// Re-export trueno-viz for visualization
25pub use trueno_viz;
26
27#[cfg(test)]
28mod tests {
29    use super::*;
30
31    #[test]
32    fn test_error_has_actionable_message() {
33        let err = EntrenarError::ConfigNotFound {
34            path: "/path/to/config.yaml".into(),
35        };
36        let msg = err.to_string();
37        assert!(msg.contains("config.yaml"));
38        assert!(msg.contains("not found"));
39    }
40
41    #[test]
42    fn test_table_builder_creates_valid_table() {
43        let table = TableBuilder::new()
44            .headers(vec!["Name", "Value"])
45            .row(vec!["test", "123"])
46            .build();
47
48        assert_eq!(table.headers().len(), 2);
49        assert_eq!(table.rows().len(), 1);
50    }
51
52    #[test]
53    fn test_output_format_parsing() {
54        assert!(matches!(
55            "json".parse::<OutputFormat>(),
56            Ok(OutputFormat::Json)
57        ));
58        assert!(matches!(
59            "table".parse::<OutputFormat>(),
60            Ok(OutputFormat::Table)
61        ));
62        assert!("invalid".parse::<OutputFormat>().is_err());
63    }
64}