diff --git a/Cargo.lock b/Cargo.lock index 108da68..a45f4e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -56,15 +56,6 @@ dependencies = [ "libc", ] -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - [[package]] name = "anstream" version = "0.6.11" @@ -235,19 +226,31 @@ dependencies = [ [[package]] name = "clap" -version = "2.34.0" +version = "4.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +checksum = "1e578d6ec4194633722ccf9544794b71b1385c3c027efe0c55db226fc880865c" dependencies = [ - "ansi_term", - "atty", - "bitflags 1.3.2", - "strsim 0.8.0", - "textwrap", - "unicode-width", - "vec_map", + "clap_builder", ] +[[package]] +name = "clap_builder" +version = "4.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4df4df40ec50c46000231c914968278b1eb05098cf8f1b3a518a95030e71d1c7" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_lex" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" + [[package]] name = "colorchoice" version = "1.0.0" @@ -290,7 +293,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim 0.10.0", + "strsim", "syn 1.0.109", ] @@ -1576,12 +1579,6 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" -[[package]] -name = "strsim" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - [[package]] name = "strsim" version = "0.10.0" @@ -1670,15 +1667,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - [[package]] name = "thiserror" version = "1.0.57" @@ -1911,12 +1899,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-width" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" - [[package]] name = "unicode-xid" version = "0.2.4" @@ -2000,12 +1982,6 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - [[package]] name = "walkdir" version = "2.4.0" diff --git a/Cargo.toml b/Cargo.toml index 7cc38e8..c32e10d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2018" [dependencies] -clap = "2" +clap = { version = "=4.4", features = ["cargo"] } # We force 4.4 so we don't have to use rustc 1.74 serde = "1" serde_derive = "1" serde_json = "1" diff --git a/src/main.rs b/src/main.rs index 8a2c236..539772b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,8 @@ extern crate lazy_static; extern crate clap; +use clap::{arg, command}; + use std::{process, thread}; use std::sync::mpsc; @@ -44,25 +46,33 @@ fn main() { env_logger::init(); log::init(APP_NAME.to_string()).unwrap(); - let args = clap::App::new("faythe") - .arg(clap::Arg::with_name("config-check") - .long("config-check") - .help("Parses Faythe config file and exits") - .takes_value(false) - .required(false)) - .arg(clap::Arg::with_name("config") - .value_name("config-file") - .help("Path to Faythe config file (JSON)") - .takes_value(true) - .required(true)); + let args = command!() + .arg( + arg!(configcheck: "Parses Faythe config file and exits") + .long("config-check") + .action(clap::ArgAction::SetTrue), + ) + .arg( + arg!(config: "Path to Faythe config file (JSON)") + .help("Path to Faythe config file (JSON)") + .required(true), + ); let m = args.get_matches(); - let config_check = m.is_present("config-check"); - let config_file = m.value_of("config").unwrap().to_owned(); + + let config_check = m.get_one::("configcheck").unwrap(); + let config_file = m.get_one::("config").unwrap().to_owned(); let config = config::parse_config_file(&config_file); match config { - Ok(c) => if !config_check { run(&c); }, - Err(e) => { eprintln!("config-file parse error: {}", &e); process::exit(1); } + Ok(c) => { + if !config_check { + run(&c); + } + } + Err(e) => { + eprintln!("config-file parse error: {}", &e); + process::exit(1); + } } } @@ -71,12 +81,12 @@ fn run(config: &FaytheConfig) { let mut threads = Vec::new(); for c in &config.kube_monitor_configs { - let container = ConfigContainer{ + let container = ConfigContainer { faythe_config: config.clone(), - monitor_config: MonitorConfig::Kube(c.to_owned()) + monitor_config: MonitorConfig::Kube(c.to_owned()), }; let tx_ = tx.clone(); - threads.push(thread::spawn(move || { monitor::monitor_k8s(container,tx_) })); + threads.push(thread::spawn(move || monitor::monitor_k8s(container, tx_))); } for c in &config.file_monitor_configs { let container = ConfigContainer { @@ -99,10 +109,12 @@ fn run(config: &FaytheConfig) { })); } let config_ = config.clone(); - threads.push(thread::spawn(move || { issuer::process(config_, rx) })); + threads.push(thread::spawn(move || issuer::process(config_, rx))); if threads.len() < 2 { - panic!("No monitors started! Did you forget to add monitor configuration to the config file?") + panic!( + "No monitors started! Did you forget to add monitor configuration to the config file?" + ) } let metrics_port = config.metrics_port;