feat: implement clap
This commit is contained in:
35
src/main.rs
35
src/main.rs
@@ -1,6 +1,7 @@
|
||||
use discord_client::DiscordNotifier;
|
||||
use dotenvy::dotenv;
|
||||
use system_monitor::SystemMonitor;
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
mod app {
|
||||
pub mod ports;
|
||||
@@ -23,7 +24,24 @@ mod actors {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(name = "node-notifier")]
|
||||
#[command(about = "A system monitoring and notification tool")]
|
||||
struct Cli {
|
||||
#[command(subcommand)]
|
||||
command: Commands,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Commands {
|
||||
/// Monitor system and alert on threshold violations
|
||||
Run,
|
||||
/// Send all system metrics notification
|
||||
Get,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let cli = Cli::parse();
|
||||
dotenv().ok();
|
||||
|
||||
let notifier = DiscordNotifier::new(
|
||||
@@ -46,11 +64,16 @@ fn main() {
|
||||
Box::new(formatter),
|
||||
);
|
||||
|
||||
if let Err(e) = service.alert_on_threshold_violation() {
|
||||
eprintln!("Error during threshold violation check: {}", e);
|
||||
}
|
||||
|
||||
if let Err(e) = service.send_all_metrics_notification() {
|
||||
eprintln!("Error sending final notification: {}", e);
|
||||
match cli.command {
|
||||
Commands::Run => {
|
||||
if let Err(e) = service.alert_on_threshold_violation() {
|
||||
eprintln!("Error during threshold violation check: {}", e);
|
||||
}
|
||||
}
|
||||
Commands::Get => {
|
||||
if let Err(e) = service.send_all_metrics_notification() {
|
||||
eprintln!("Error sending final notification: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user