workhelix_cli_common/lib.rs
1//! Common functionality for Workhelix Rust CLI tools.
2//!
3//! This library provides shared functionality for CLI tools including:
4//! - Shell completion generation
5//! - Health check framework
6//! - License display
7//! - Terminal output utilities
8//!
9//! # Example Usage
10//!
11//! ```no_run
12//! use workhelix_cli_common::{
13//! RepoInfo, DoctorChecks, DoctorCheck,
14//! completions, doctor, license,
15//! };
16//! use clap::Parser;
17//!
18//! #[derive(Parser)]
19//! struct Cli {
20//! // your CLI definition
21//! }
22//!
23//! struct MyTool;
24//!
25//! impl DoctorChecks for MyTool {
26//! fn repo_info() -> RepoInfo {
27//! RepoInfo::new("myorg", "mytool")
28//! }
29//!
30//! fn current_version() -> &'static str {
31//! env!("CARGO_PKG_VERSION")
32//! }
33//!
34//! fn tool_checks(&self) -> Vec<DoctorCheck> {
35//! vec![
36//! DoctorCheck::file_exists("~/.config/mytool/config.toml"),
37//! ]
38//! }
39//! }
40//!
41//! // Generate completions
42//! completions::generate_completions::<Cli>(clap_complete::Shell::Bash);
43//!
44//! // Run health check
45//! let tool = MyTool;
46//! let exit_code = doctor::run_doctor(&tool);
47//! ```
48
49// Re-export main types and traits
50pub use doctor::DoctorChecks;
51pub use license::LicenseType;
52pub use types::{DoctorCheck, RepoInfo};
53
54// Public modules
55pub mod completions;
56pub mod doctor;
57pub mod license;
58pub mod output;
59pub mod types;
60
61// Re-export commonly used items
62pub use completions::generate_completions;
63pub use doctor::run_doctor;
64pub use license::display_license;
65
66#[cfg(test)]
67mod tests {
68 use super::*;
69
70 #[test]
71 fn test_repo_info_creation() {
72 let repo = RepoInfo::new("workhelix", "test");
73 assert_eq!(repo.owner, "workhelix");
74 assert_eq!(repo.name, "test");
75 }
76
77 #[test]
78 fn test_doctor_check_creation() {
79 let check = DoctorCheck::pass("test");
80 assert!(check.passed);
81
82 let check = DoctorCheck::fail("test", "failed");
83 assert!(!check.passed);
84 }
85
86 #[test]
87 fn test_license_type() {
88 assert_eq!(LicenseType::MIT.name(), "MIT");
89 assert_eq!(LicenseType::Apache2.name(), "Apache-2.0");
90 assert_eq!(LicenseType::CC0.name(), "CC0-1.0");
91 }
92}