From b898f548800e20f6aea8f0dc4249402068f70a33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolphe=20Br=C3=A9ard?= Date: Mon, 19 Dec 2022 13:14:48 +0100 Subject: [PATCH] Fix the flags --- acmed/src/main.rs | 22 +++++++++++++--------- tacd/src/main.rs | 20 ++++++++++++-------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/acmed/src/main.rs b/acmed/src/main.rs index 2a30bf3..47f6d89 100644 --- a/acmed/src/main.rs +++ b/acmed/src/main.rs @@ -4,7 +4,7 @@ use acme_common::crypto::{ }; use acme_common::logs::{set_log_system, DEFAULT_LOG_LEVEL}; use acme_common::{clean_pid_file, init_server}; -use clap::{Arg, Command}; +use clap::{Arg, ArgAction, Command}; use log::error; mod account; @@ -84,19 +84,22 @@ fn main() { Arg::new("to-syslog") .long("log-syslog") .help("Sends log messages via syslog") - .conflicts_with("to-stderr"), + .conflicts_with("to-stderr") + .action(ArgAction::SetTrue), ) .arg( Arg::new("to-stderr") .long("log-stderr") .help("Prints log messages to the standard error output") - .conflicts_with("to-syslog"), + .conflicts_with("to-syslog") + .action(ArgAction::SetTrue), ) .arg( Arg::new("foreground") .short('f') .long("foreground") - .help("Runs in the foreground"), + .help("Runs in the foreground") + .action(ArgAction::SetTrue), ) .arg( Arg::new("pid-file") @@ -112,22 +115,23 @@ fn main() { Arg::new("no-pid-file") .long("no-pid-file") .help("Do not create any PID file") - .conflicts_with("pid-file"), + .conflicts_with("pid-file") + .action(ArgAction::SetTrue), ) .arg( Arg::new("root-cert") .long("root-cert") .help("Add a root certificate to the trust store (can be set multiple times)") .num_args(1) - .action(clap::ArgAction::Append) + .action(ArgAction::Append) .value_name("FILE"), ) .get_matches(); match set_log_system( matches.get_one::("log-level").map(|e| e.as_str()), - matches.contains_id("to-syslog"), - matches.contains_id("to-stderr"), + matches.get_flag("to-syslog"), + matches.get_flag("to-stderr"), ) { Ok(_) => {} Err(e) => { @@ -147,7 +151,7 @@ fn main() { .unwrap_or(DEFAULT_CONFIG_FILE); let pid_file = matches.get_one::("pid-file").map(|e| e.as_str()); - init_server(matches.contains_id("foreground"), pid_file); + init_server(matches.get_flag("foreground"), pid_file); let mut srv = match MainEventLoop::new(config_file, &root_certs) { Ok(s) => s, diff --git a/tacd/src/main.rs b/tacd/src/main.rs index 05e631c..b47e13a 100644 --- a/tacd/src/main.rs +++ b/tacd/src/main.rs @@ -8,7 +8,7 @@ use acme_common::error::Error; use acme_common::logs::{set_log_system, DEFAULT_LOG_LEVEL}; use acme_common::{clean_pid_file, to_idna}; use clap::builder::PossibleValuesParser; -use clap::{Arg, ArgMatches, Command}; +use clap::{Arg, ArgAction, ArgMatches, Command}; use log::{debug, error, info}; use std::fs::File; use std::io::{self, Read}; @@ -49,7 +49,7 @@ fn get_acme_value(cnf: &ArgMatches, opt: &str, opt_file: &str) -> Result Result<(), Error> { acme_common::init_server( - cnf.contains_id("foreground"), + cnf.get_flag("foreground"), cnf.get_one::("pid-file").map(|e| e.as_str()), ); let domain = get_acme_value(cnf, "domain", "domain-file")?; @@ -161,19 +161,22 @@ fn main() { Arg::new("to-syslog") .long("log-syslog") .help("Sends log messages via syslog") - .conflicts_with("to-stderr"), + .conflicts_with("to-stderr") + .action(ArgAction::SetTrue), ) .arg( Arg::new("to-stderr") .long("log-stderr") .help("Prints log messages to the standard error output") - .conflicts_with("to-syslog"), + .conflicts_with("to-syslog") + .action(ArgAction::SetTrue), ) .arg( Arg::new("foreground") .long("foreground") .short('f') - .help("Runs in the foreground"), + .help("Runs in the foreground") + .action(ArgAction::SetTrue), ) .arg( Arg::new("pid-file") @@ -189,14 +192,15 @@ fn main() { Arg::new("no-pid-file") .long("no-pid-file") .help("Do not create any PID file") - .conflicts_with("pid-file"), + .conflicts_with("pid-file") + .action(ArgAction::SetTrue), ) .get_matches(); match set_log_system( matches.get_one::("log-level").map(|e| e.as_str()), - matches.contains_id("to-syslog"), - matches.contains_id("to-stderr"), + matches.get_flag("to-syslog"), + matches.get_flag("to-stderr"), ) { Ok(_) => {} Err(e) => {