torsh_cli/
lib.rs

1//! ToRSh CLI Library
2//!
3//! This library provides the core functionality for the ToRSh command-line interface,
4//! including configuration management, command implementations, and utilities.
5
6#![cfg_attr(docsrs, feature(doc_cfg))]
7
8pub mod commands;
9pub mod config;
10pub mod utils;
11
12// Re-export commonly used types
13pub use config::Config;
14
15/// CLI version information
16pub const VERSION: &str = env!("CARGO_PKG_VERSION");
17pub const VERSION_MAJOR: u32 = 0;
18pub const VERSION_MINOR: u32 = 1;
19pub const VERSION_PATCH: u32 = 0;
20
21/// Check if CLI version is compatible with required version
22pub fn check_version(required_major: u32, required_minor: u32) -> anyhow::Result<()> {
23    if VERSION_MAJOR < required_major
24        || (VERSION_MAJOR == required_major && VERSION_MINOR < required_minor)
25    {
26        anyhow::bail!(
27            "ToRSh CLI version {}.{} or higher required, but got {}.{}",
28            required_major,
29            required_minor,
30            VERSION_MAJOR,
31            VERSION_MINOR
32        );
33    }
34    Ok(())
35}
36
37#[cfg(test)]
38mod tests {
39    use super::*;
40
41    #[test]
42    fn test_version_check() {
43        assert!(check_version(0, 1).is_ok());
44        assert!(check_version(1, 0).is_err());
45    }
46}