Skip to content

Commit

Permalink
build(cargo): bump clap to 4.4
Browse files Browse the repository at this point in the history
Signed-off-by: Christina Sørensen <[email protected]>
  • Loading branch information
cafkafk committed Feb 19, 2024
1 parent 43f117b commit 4b2c8df
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 67 deletions.
68 changes: 22 additions & 46 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
52 changes: 32 additions & 20 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ extern crate lazy_static;

extern crate clap;

use clap::{arg, command};

use std::{process, thread};

use std::sync::mpsc;
Expand Down Expand Up @@ -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::<bool>("configcheck").unwrap();
let config_file = m.get_one::<String>("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);
}
}
}

Expand All @@ -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 {
Expand All @@ -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;
Expand Down

0 comments on commit 4b2c8df

Please sign in to comment.