modcli/
lib.rs

1pub mod loader;
2pub mod config;
3pub mod input;
4pub mod output;
5pub mod command;
6pub mod parser;
7pub mod console;
8pub mod shell_extensions;
9pub mod shell_commands;
10
11use crate::loader::CommandRegistry;
12pub use crate::command::Command as CliCustom;
13
14#[cfg(feature = "internal-commands")]
15pub mod commands;
16
17#[cfg(feature = "custom-commands")]
18pub mod custom;
19
20
21/// Represents a CLI application
22pub struct ModCli {
23    pub registry: CommandRegistry,
24}
25
26impl ModCli {
27    /// Creates a new ModCli instance
28    ///
29    /// # Example
30    /// ```
31    /// use modcli::ModCli;
32    /// let cli = ModCli::new();
33    /// ```
34    ///
35    /// # Arguments
36    /// * `args` - A vector of command-line arguments
37    ///
38    /// # Returns
39    /// A new instance of `ModCli`
40    pub fn new() -> Self {
41        Self {
42            registry: CommandRegistry::new(),
43        }
44    }
45
46    /// Sets the command prefix
47    pub fn set_prefix(&mut self, prefix: &str) {
48        self.registry.set_prefix(prefix);
49    }
50
51    /// Gets the command prefix
52    pub fn get_prefix(&self) -> &str {
53        self.registry.get_prefix()
54    }
55
56    /// Preferred constructor: sets config path before CLI boot
57    pub fn with_config(path: &str) -> Self {
58        config::set_path(path);
59        Self::new()
60    }
61
62    pub fn run(&mut self, args: Vec<String>) {
63        if args.is_empty() {
64            eprintln!("No command provided.");
65            return;
66        }
67
68        let command = &args[0];
69        let rest = &args[1..];
70
71        self.registry.execute(command, rest);
72    }
73}
74
75/// Returns the version of the ModCLI framework (from modcli/Cargo.toml)
76pub fn modcli_version() -> &'static str {
77    env!("CARGO_PKG_VERSION")
78}