blob: 670a2bf28bba15bd2fc78452e7ab268d0f69e538 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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"),
)
}
|