Skip to main content

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
6pub mod commands;
7pub mod config;
8pub mod utils;
9
10// Re-export commonly used types
11pub use config::Config;
12
13/// CLI version information
14pub const VERSION: &str = env!("CARGO_PKG_VERSION");
15pub const VERSION_MAJOR: u32 = 0;
16pub const VERSION_MINOR: u32 = 1;
17pub const VERSION_PATCH: u32 = 0;
18
19/// Check if CLI version is compatible with required version
20pub fn check_version(required_major: u32, required_minor: u32) -> anyhow::Result<()> {
21    if VERSION_MAJOR < required_major
22        || (VERSION_MAJOR == required_major && VERSION_MINOR < required_minor)
23    {
24        anyhow::bail!(
25            "ToRSh CLI version {}.{} or higher required, but got {}.{}",
26            required_major,
27            required_minor,
28            VERSION_MAJOR,
29            VERSION_MINOR
30        );
31    }
32    Ok(())
33}
34
35#[cfg(test)]
36mod tests {
37    use super::*;
38
39    #[test]
40    fn test_version_check() {
41        assert!(check_version(0, 1).is_ok());
42        assert!(check_version(1, 0).is_err());
43    }
44}