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