feat: implement clap

This commit is contained in:
2025-08-10 16:38:29 +02:00
parent e7b35953ca
commit 23b331a4f8
3 changed files with 151 additions and 6 deletions

View File

@@ -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);
}
}
}
}