diff --git a/Cargo.toml b/Cargo.toml index 3e7d020..4f6b3d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ debug = false [dependencies] anyhow = "1.0.93" chrono = "0.4.38" +clap = { version = "4.5.21", features = ["derive"] } env_logger = "0.11.3" inotify = "0.10.2" log = "0.4.22" diff --git a/src/main.rs b/src/main.rs index 6f161d0..3375948 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ mod options; mod utils; +use clap::Parser; use log::{error, info}; use options::config::*; use options::logger::setup_logger; @@ -10,9 +11,15 @@ use std::sync::Arc; use std::time::Duration; use tokio::sync::mpsc; use utils::*; +use options::preboot::*; #[tokio::main(flavor = "multi_thread")] async fn main() { + use options::structs::PrebootParams; + let a = PrebootParams::parse(); + println!("{:?}", a); + + let _ = setup_logger(); info!("Runner is configurating..."); diff --git a/src/options.rs b/src/options.rs index d9f9b03..0b4b3cf 100644 --- a/src/options.rs +++ b/src/options.rs @@ -4,3 +4,4 @@ pub mod config; pub mod logger; pub mod signals; pub mod structs; +pub mod preboot; \ No newline at end of file diff --git a/src/options/preboot.rs b/src/options/preboot.rs new file mode 100644 index 0000000..bc347b9 --- /dev/null +++ b/src/options/preboot.rs @@ -0,0 +1,10 @@ +// module to handle pre-boot params of the monitor +use super::structs::PrebootParams; + + + + + + + +// unit tests of prebot params parsing mech \ No newline at end of file diff --git a/src/options/structs.rs b/src/options/structs.rs index 40957c5..405d7d2 100644 --- a/src/options/structs.rs +++ b/src/options/structs.rs @@ -2,11 +2,63 @@ use std::net::Ipv4Addr; use serde::{Deserialize, Serialize}; +use clap::Parser; /// # an Error enum (next will be deleted and replaced) pub enum CustomError { Fatal, } + +#[derive(clap::ValueEnum, Debug, Clone)] +enum MetricsPrebootParams { + Full, + System, + Processes, + Net, + None, +} + +impl std::fmt::Display for MetricsPrebootParams { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match self { + MetricsPrebootParams::Full => write!(f, "full"), + MetricsPrebootParams::System => write!(f, "system"), + MetricsPrebootParams::Processes => write!(f, "processes"), + MetricsPrebootParams::Net => write!(f, "net"), + MetricsPrebootParams::None => write!(f, "none"), + } + } +} + +#[derive(Debug, Parser)] +pub struct PrebootParams { + // actions + #[arg(long = "no-hagent", action, conflicts_with="socket_path", help="To disable work with host-agent")] + no_hostagent : bool, + #[arg(long = "no-logs", action, conflicts_with="log_to", help="To disable logs")] + no_logs: bool, + #[arg(long = "refresh-logs", action, conflicts_with="no_logs", help="To clear logs directory")] + refresh_logs : bool, + #[arg(long = "no-remote-config", action, help="To disable work with remote config server", conflicts_with="no_sub")] + no_remote_config : bool, + #[arg(long = "no-sub", action, help="To disable subscription mechanism", conflicts_with="no_remote_config")] + no_sub : bool, + + // params (socket_path, log_to, remote_server_url, config) + #[arg(long = "socket-path", default_value=None, conflicts_with="no_hostagent", help="To set .sock file's path used in communication with host-agent")] + socket_path : Option, + #[arg(long = "log-to", default_value=None, conflicts_with="no_logs", help="To set a path to logs directory")] + log_to : Option, + #[arg(long = "remote-server-url", default_value="redis://localhost", conflicts_with="no_remote_config", help = "To set url of remote config server using in remote config pulling mechanism")] + remote_server_url : String, + #[arg(long = "config", short, default_value="settings.json", help="To set local config file path")] + config : String, + + // value enum params (metrics) + #[arg(long = "metrics", short, default_value_t=MetricsPrebootParams::Full, help="To set metrics grubbing mode")] + metrics: MetricsPrebootParams, +} + #[derive(Debug, PartialEq)] pub enum ConfigActuality { Local,