diff options
Diffstat (limited to 'mullvad_daemon/src/cli.rs')
| -rw-r--r-- | mullvad_daemon/src/cli.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/mullvad_daemon/src/cli.rs b/mullvad_daemon/src/cli.rs new file mode 100644 index 0000000000..670a2bf28b --- /dev/null +++ b/mullvad_daemon/src/cli.rs @@ -0,0 +1,45 @@ +use clap::{App, Arg}; +use log; + +use std::path::PathBuf; + +pub struct Config { + pub log_level: log::LogLevelFilter, + pub log_file: Option<PathBuf>, +} + +pub fn get_config() -> Config { + let app = create_app(); + let matches = app.get_matches(); + + let log_level = match matches.occurrences_of("v") { + 0 => log::LogLevelFilter::Info, + 1 => log::LogLevelFilter::Debug, + _ => log::LogLevelFilter::Trace, + }; + let log_file = matches.value_of_os("log_file").map(PathBuf::from); + + Config { + log_level, + log_file, + } +} + +fn create_app() -> App<'static, 'static> { + App::new(::CRATE_NAME) + .version(crate_version!()) + .author(crate_authors!()) + .about(crate_description!()) + .arg( + Arg::with_name("v") + .short("v") + .multiple(true) + .help("Sets the level of verbosity."), + ) + .arg( + Arg::with_name("log_file") + .long("log") + .takes_value(true) + .help("Activates file logging to the given path"), + ) +} |
