Browse Source

Fix the flags

pull/76/head
Rodolphe Bréard 2 years ago
parent
commit
b898f54880
  1. 22
      acmed/src/main.rs
  2. 20
      tacd/src/main.rs

22
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::logs::{set_log_system, DEFAULT_LOG_LEVEL};
use acme_common::{clean_pid_file, init_server}; use acme_common::{clean_pid_file, init_server};
use clap::{Arg, Command};
use clap::{Arg, ArgAction, Command};
use log::error; use log::error;
mod account; mod account;
@ -84,19 +84,22 @@ fn main() {
Arg::new("to-syslog") Arg::new("to-syslog")
.long("log-syslog") .long("log-syslog")
.help("Sends log messages via syslog") .help("Sends log messages via syslog")
.conflicts_with("to-stderr"),
.conflicts_with("to-stderr")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new("to-stderr") Arg::new("to-stderr")
.long("log-stderr") .long("log-stderr")
.help("Prints log messages to the standard error output") .help("Prints log messages to the standard error output")
.conflicts_with("to-syslog"),
.conflicts_with("to-syslog")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new("foreground") Arg::new("foreground")
.short('f') .short('f')
.long("foreground") .long("foreground")
.help("Runs in the foreground"),
.help("Runs in the foreground")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new("pid-file") Arg::new("pid-file")
@ -112,22 +115,23 @@ fn main() {
Arg::new("no-pid-file") Arg::new("no-pid-file")
.long("no-pid-file") .long("no-pid-file")
.help("Do not create any PID file") .help("Do not create any PID file")
.conflicts_with("pid-file"),
.conflicts_with("pid-file")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new("root-cert") Arg::new("root-cert")
.long("root-cert") .long("root-cert")
.help("Add a root certificate to the trust store (can be set multiple times)") .help("Add a root certificate to the trust store (can be set multiple times)")
.num_args(1) .num_args(1)
.action(clap::ArgAction::Append)
.action(ArgAction::Append)
.value_name("FILE"), .value_name("FILE"),
) )
.get_matches(); .get_matches();
match set_log_system( match set_log_system(
matches.get_one::<String>("log-level").map(|e| e.as_str()), matches.get_one::<String>("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(_) => {} Ok(_) => {}
Err(e) => { Err(e) => {
@ -147,7 +151,7 @@ fn main() {
.unwrap_or(DEFAULT_CONFIG_FILE); .unwrap_or(DEFAULT_CONFIG_FILE);
let pid_file = matches.get_one::<String>("pid-file").map(|e| e.as_str()); let pid_file = matches.get_one::<String>("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) { let mut srv = match MainEventLoop::new(config_file, &root_certs) {
Ok(s) => s, Ok(s) => s,

20
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::logs::{set_log_system, DEFAULT_LOG_LEVEL};
use acme_common::{clean_pid_file, to_idna}; use acme_common::{clean_pid_file, to_idna};
use clap::builder::PossibleValuesParser; use clap::builder::PossibleValuesParser;
use clap::{Arg, ArgMatches, Command};
use clap::{Arg, ArgAction, ArgMatches, Command};
use log::{debug, error, info}; use log::{debug, error, info};
use std::fs::File; use std::fs::File;
use std::io::{self, Read}; use std::io::{self, Read};
@ -49,7 +49,7 @@ fn get_acme_value(cnf: &ArgMatches, opt: &str, opt_file: &str) -> Result<String,
fn init(cnf: &ArgMatches) -> Result<(), Error> { fn init(cnf: &ArgMatches) -> Result<(), Error> {
acme_common::init_server( acme_common::init_server(
cnf.contains_id("foreground"),
cnf.get_flag("foreground"),
cnf.get_one::<String>("pid-file").map(|e| e.as_str()), cnf.get_one::<String>("pid-file").map(|e| e.as_str()),
); );
let domain = get_acme_value(cnf, "domain", "domain-file")?; let domain = get_acme_value(cnf, "domain", "domain-file")?;
@ -161,19 +161,22 @@ fn main() {
Arg::new("to-syslog") Arg::new("to-syslog")
.long("log-syslog") .long("log-syslog")
.help("Sends log messages via syslog") .help("Sends log messages via syslog")
.conflicts_with("to-stderr"),
.conflicts_with("to-stderr")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new("to-stderr") Arg::new("to-stderr")
.long("log-stderr") .long("log-stderr")
.help("Prints log messages to the standard error output") .help("Prints log messages to the standard error output")
.conflicts_with("to-syslog"),
.conflicts_with("to-syslog")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new("foreground") Arg::new("foreground")
.long("foreground") .long("foreground")
.short('f') .short('f')
.help("Runs in the foreground"),
.help("Runs in the foreground")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new("pid-file") Arg::new("pid-file")
@ -189,14 +192,15 @@ fn main() {
Arg::new("no-pid-file") Arg::new("no-pid-file")
.long("no-pid-file") .long("no-pid-file")
.help("Do not create any PID file") .help("Do not create any PID file")
.conflicts_with("pid-file"),
.conflicts_with("pid-file")
.action(ArgAction::SetTrue),
) )
.get_matches(); .get_matches();
match set_log_system( match set_log_system(
matches.get_one::<String>("log-level").map(|e| e.as_str()), matches.get_one::<String>("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(_) => {} Ok(_) => {}
Err(e) => { Err(e) => {

Loading…
Cancel
Save