Browse Source

Improve the CLI

Some default values were missing. Some descriptions has been rephrased.
pull/39/head
Rodolphe Breard 4 years ago
parent
commit
c7263703d1
  1. 4
      acme_common/src/logs.rs
  2. 19
      acmed/src/main.rs
  3. 21
      tacd/src/main.rs

4
acme_common/src/logs.rs

@ -3,8 +3,8 @@ use env_logger::Builder;
use log::LevelFilter; use log::LevelFilter;
use syslog::Facility; use syslog::Facility;
const DEFAULT_LOG_SYSTEM: LogSystem = LogSystem::SysLog;
const DEFAULT_LOG_LEVEL: LevelFilter = LevelFilter::Warn;
pub const DEFAULT_LOG_SYSTEM: LogSystem = LogSystem::SysLog;
pub const DEFAULT_LOG_LEVEL: LevelFilter = LevelFilter::Warn;
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub enum LogSystem { pub enum LogSystem {

19
acmed/src/main.rs

@ -1,4 +1,5 @@
use crate::main_event_loop::MainEventLoop; use crate::main_event_loop::MainEventLoop;
use acme_common::logs::{set_log_system, DEFAULT_LOG_LEVEL};
use acme_common::{clean_pid_file, crypto, init_server}; use acme_common::{clean_pid_file, crypto, init_server};
use clap::{App, Arg}; use clap::{App, Arg};
use log::error; use log::error;
@ -49,6 +50,7 @@ fn main() {
env!("ACMED_HTTP_LIB_NAME"), env!("ACMED_HTTP_LIB_NAME"),
env!("ACMED_HTTP_LIB_VERSION") env!("ACMED_HTTP_LIB_VERSION")
); );
let default_log_level = DEFAULT_LOG_LEVEL.to_string().to_lowercase();
let matches = App::new(APP_NAME) let matches = App::new(APP_NAME)
.version(APP_VERSION) .version(APP_VERSION)
.long_version(full_version.as_str()) .long_version(full_version.as_str())
@ -56,9 +58,10 @@ fn main() {
Arg::with_name("config") Arg::with_name("config")
.short("c") .short("c")
.long("config") .long("config")
.help("Specify an alternative configuration file")
.help("Path to the main configuration file")
.takes_value(true) .takes_value(true)
.value_name("FILE"),
.value_name("FILE")
.default_value(&DEFAULT_CONFIG_FILE),
) )
.arg( .arg(
Arg::with_name("log-level") Arg::with_name("log-level")
@ -66,7 +69,8 @@ fn main() {
.help("Specify the log level") .help("Specify the log level")
.takes_value(true) .takes_value(true)
.value_name("LEVEL") .value_name("LEVEL")
.possible_values(&["error", "warn", "info", "debug", "trace"]),
.possible_values(&["error", "warn", "info", "debug", "trace"])
.default_value(&default_log_level),
) )
.arg( .arg(
Arg::with_name("to-syslog") Arg::with_name("to-syslog")
@ -89,21 +93,22 @@ fn main() {
.arg( .arg(
Arg::with_name("pid-file") Arg::with_name("pid-file")
.long("pid-file") .long("pid-file")
.help("Specifies the location of the PID file")
.help("Path to the PID file")
.takes_value(true) .takes_value(true)
.value_name("FILE"),
.value_name("FILE")
.default_value(&DEFAULT_PID_FILE),
) )
.arg( .arg(
Arg::with_name("root-cert") Arg::with_name("root-cert")
.long("root-cert") .long("root-cert")
.help("Add a root certificate to the trust store")
.help("Add a root certificate to the trust store (can be set multiple times)")
.takes_value(true) .takes_value(true)
.multiple(true) .multiple(true)
.value_name("FILE"), .value_name("FILE"),
) )
.get_matches(); .get_matches();
match acme_common::logs::set_log_system(
match set_log_system(
matches.value_of("log-level"), matches.value_of("log-level"),
matches.is_present("log-syslog"), matches.is_present("log-syslog"),
matches.is_present("to-stderr"), matches.is_present("to-stderr"),

21
tacd/src/main.rs

@ -3,6 +3,7 @@ mod openssl_server;
use crate::openssl_server::start as server_start; use crate::openssl_server::start as server_start;
use acme_common::crypto::{KeyType, X509Certificate}; use acme_common::crypto::{KeyType, X509Certificate};
use acme_common::error::Error; use acme_common::error::Error;
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::{App, Arg, ArgMatches}; use clap::{App, Arg, ArgMatches};
use log::{debug, error, info}; use log::{debug, error, info};
@ -62,15 +63,17 @@ fn init(cnf: &ArgMatches) -> Result<(), Error> {
fn main() { fn main() {
let default_crt_key_type = DEFAULT_CRT_KEY_TYPE.to_string(); let default_crt_key_type = DEFAULT_CRT_KEY_TYPE.to_string();
let default_log_level = DEFAULT_LOG_LEVEL.to_string().to_lowercase();
let matches = App::new(APP_NAME) let matches = App::new(APP_NAME)
.version(APP_VERSION) .version(APP_VERSION)
.arg( .arg(
Arg::with_name("listen") Arg::with_name("listen")
.long("listen") .long("listen")
.short("l") .short("l")
.help("Specifies the host and port to listen on")
.help("Host and port to listen on")
.takes_value(true) .takes_value(true)
.value_name("host:port|unix:path"),
.value_name("host:port|unix:path")
.default_value(&DEFAULT_LISTEN_ADDR)
) )
.arg( .arg(
Arg::with_name("domain") Arg::with_name("domain")
@ -121,7 +124,8 @@ fn main() {
.help("Specify the log level") .help("Specify the log level")
.takes_value(true) .takes_value(true)
.value_name("LEVEL") .value_name("LEVEL")
.possible_values(&["error", "warn", "info", "debug", "trace"]),
.possible_values(&["error", "warn", "info", "debug", "trace"])
.default_value(&default_log_level)
) )
.arg( .arg(
Arg::with_name("to-syslog") Arg::with_name("to-syslog")
@ -133,24 +137,25 @@ fn main() {
Arg::with_name("to-stderr") Arg::with_name("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("log-syslog"),
.conflicts_with("to-syslog"),
) )
.arg( .arg(
Arg::with_name("foreground") Arg::with_name("foreground")
.long("foreground") .long("foreground")
.short("f") .short("f")
.help("Runs in the foreground"),
.help("Runs in the foreground")
) )
.arg( .arg(
Arg::with_name("pid-file") Arg::with_name("pid-file")
.long("pid-file") .long("pid-file")
.help("Specifies the location of the PID file")
.help("Path to the PID file")
.takes_value(true) .takes_value(true)
.value_name("FILE"),
.value_name("FILE")
.default_value(&DEFAULT_PID_FILE)
) )
.get_matches(); .get_matches();
match acme_common::logs::set_log_system(
match set_log_system(
matches.value_of("log-level"), matches.value_of("log-level"),
matches.is_present("log-syslog"), matches.is_present("log-syslog"),
matches.is_present("to-stderr"), matches.is_present("to-stderr"),

Loading…
Cancel
Save