use clap::{Parser, Subcommand}; use metrics_models::MetricsMode; #[derive(Debug, Parser, serde::Serialize, serde::Deserialize)] pub struct Cli { #[arg( short, default_value = "noxis-rs.sock", help = "explicit specify of NOXIS Socket file" )] pub socket: String, #[command(subcommand, help = "to manage Noxis work")] pub command: Commands, } #[derive(Debug, Subcommand, serde::Serialize, serde::Deserialize)] pub enum Commands { #[command(about = "To get info about current Noxis status")] Status, #[command(about = "To start Noxis process")] Start(StartAction), #[command(about = "To stop Noxis process")] Stop, #[command(about = "To restart Noxis process")] Restart(StartAction), #[command(about = "To get list of processes that are being monitoring")] Processes, // process command #[command(about = "To manage current process that is being monitoring")] Process(ProcessCommand), #[command(about = "To manage config settings")] Config(ConfigCommand), #[command(about = "To inspect system metrics in restricted mode")] Inspect(MetricsCommand), } #[derive(Debug, Parser, serde::Serialize, serde::Deserialize)] pub struct MetricsCommand { #[command(subcommand)] pub mode: MetricsMode, } #[derive(Debug, Parser, serde::Serialize, serde::Deserialize)] pub struct StartAction { #[arg( long="with-flags", num_args = 1.., value_delimiter = ' ' )] pub flags: Vec, } #[derive(Debug, Parser, serde::Serialize, serde::Deserialize)] pub struct ConfigCommand { #[command(subcommand)] pub action: ConfigAction, } #[derive(Debug, Subcommand, serde::Serialize, serde::Deserialize)] pub enum ConfigAction { #[command(about = "To change current Noxis configuration")] Local(LocalConfig), #[command(about = "To change credentials of the remote config server")] Remote, #[command(about = "To reset all config settings")] Reset, #[command(about = "To get current Noxis configuration", name = "ls")] Show(EnvConfig), } #[derive(Debug, Parser, serde::Serialize, serde::Deserialize)] pub struct EnvConfig { // flag #[arg(long = "env", action, help = "to read environment vars configuration")] pub is_env: bool, } #[derive(Debug, Parser, serde::Serialize, serde::Deserialize)] pub struct LocalConfig { // flag #[arg(long = "json", action, help = "to read following input as JSON")] pub is_json: bool, // value #[arg(help = "path to config file or config String (with --json flag)")] pub config: String, } #[derive(Debug, Parser, serde::Serialize, serde::Deserialize)] pub struct ProcessCommand { #[arg(help = "name of needed process")] pub process: String, #[command(subcommand, help = "To get current process's status")] pub action: ProcessAction, } #[derive(Debug, Subcommand, serde::Serialize, serde::Deserialize)] pub enum ProcessAction { #[command(about = "To get info about current process status")] Status, #[command(about = "To start current process")] Start, #[command(about = "To stop current process")] Stop, #[command(about = "To freeze (hybernaze) current process")] Freeze, #[command(about = "To unfreeze (unhybernaze) current process")] Unfreeze, #[command(about = "To restart current process")] Restart, #[command(about = "To get info about current process's dependencies")] Deps, #[command(about = "To get info about current process's files-dependencies")] Files, #[command(about = "To get info about current process's services-dependencies")] Services, } pub mod metrics_models { #[derive(Debug, clap::Parser, serde::Serialize, serde::Deserialize)] pub enum MetricsMode { #[command(about = "To capture all metrics about undercontrolled system")] Full, // system #[command(about = "To capture general host info")] Host, #[command(about = "To capture detailed CPU metrics")] Cpu, #[command(about = "To capture RAM metrics")] Ram, #[command(about = "To capture disk environment metrics")] Rom, #[command(about = "To capture system net interfaces metrics")] Network, // processes #[command(about = "To capture monitoring processes metrics")] Processes, // Config } } impl Cli { pub fn validate_socket(mut self) -> Self { if let Ok(path) = std::env::var("NOXIS_SOCKET_PATH") { self.socket = path; } self } }