nerve/cli/
mod.rs

1//! CLI Module for Nerve Framework System Debugging
2//!
3//! Provides command-line interface for system monitoring, debugging,
4//! and performance analysis of the Nerve Framework components.
5
6pub mod commands;
7pub mod config;
8pub mod output;
9
10use clap::{Parser, Subcommand};
11use std::error::Error;
12use crate::cli::commands::CliCommand;
13
14/// Main CLI application for Nerve Framework debugging
15#[derive(Parser, Debug)]
16#[command(name = "nerve-cli")]
17#[command(about = "Nerve Framework System Debugging CLI")]
18#[command(version = "0.1.0")]
19#[command(propagate_version = true)]
20pub struct Cli {
21    /// Global configuration options
22    #[command(flatten)]
23    pub config: CliConfig,
24
25    /// Subcommand to execute
26    #[command(subcommand)]
27    pub command: Commands,
28}
29
30/// Global CLI configuration options
31#[derive(Parser, Debug)]
32pub struct CliConfig {
33    /// Enable verbose output
34    #[arg(short, long, global = true)]
35    pub verbose: bool,
36
37    /// Output format (text, json, yaml)
38    #[arg(short, long, global = true, default_value = "text")]
39    pub format: String,
40
41    /// System configuration file path
42    #[arg(short, long, global = true)]
43    pub config_file: Option<String>,
44}
45
46/// Available CLI commands
47#[derive(Subcommand, Debug)]
48pub enum Commands {
49    /// Show overall system health and statistics
50    Status(commands::status::StatusCommand),
51
52    /// Memory buffer diagnostics and monitoring
53    Memory(commands::memory::MemoryCommand),
54
55    /// Thread lifecycle and watchdog status
56    Threads(commands::threads::ThreadsCommand),
57
58    /// Node registry inspection and management
59    Nodes(commands::nodes::NodesCommand),
60
61    /// Communication system diagnostics
62    Comms(commands::comms::CommsCommand),
63
64    /// Performance metrics and benchmarks
65    Perf(commands::perf::PerfCommand),
66
67    /// System configuration management
68    Config(commands::config::ConfigCommand),
69
70    /// Advanced debugging and troubleshooting
71    Debug(commands::debug::DebugCommand),
72}
73
74/// CLI application entry point
75pub struct CliApp {
76    pub cli: Cli,
77}
78
79impl CliApp {
80    /// Create a new CLI application
81    pub fn new() -> Self {
82        Self {
83            cli: Cli::parse(),
84        }
85    }
86
87    /// Run the CLI application
88    pub fn run(&self) -> Result<(), Box<dyn Error>> {
89        if self.cli.config.verbose {
90            println!("🔧 Nerve Framework CLI v0.1.0");
91            println!("📊 Running command: {:?}", self.cli.command);
92        }
93
94        match &self.cli.command {
95            Commands::Status(cmd) => cmd.execute(&self.cli.config).map_err(|e| e.into()),
96            Commands::Memory(cmd) => cmd.execute(&self.cli.config).map_err(|e| e.into()),
97            Commands::Threads(cmd) => cmd.execute(&self.cli.config).map_err(|e| e.into()),
98            Commands::Nodes(cmd) => cmd.execute(&self.cli.config).map_err(|e| e.into()),
99            Commands::Comms(cmd) => cmd.execute(&self.cli.config).map_err(|e| e.into()),
100            Commands::Perf(cmd) => cmd.execute(&self.cli.config).map_err(|e| e.into()),
101            Commands::Config(cmd) => cmd.execute(&self.cli.config).map_err(|e| e.into()),
102            Commands::Debug(cmd) => cmd.execute(&self.cli.config).map_err(|e| e.into()),
103        }
104    }
105}
106
107/// CLI error type
108#[derive(Debug, thiserror::Error)]
109pub enum CliError {
110    #[error("System error: {0}")]
111    SystemError(String),
112
113    #[error("Configuration error: {0}")]
114    ConfigError(String),
115
116    #[error("Command execution error: {0}")]
117    ExecutionError(String),
118
119    #[error("Output format error: {0}")]
120    OutputError(String),
121}
122
123impl From<Box<dyn Error>> for CliError {
124    fn from(error: Box<dyn Error>) -> Self {
125        CliError::SystemError(error.to_string())
126    }
127}