yocto/
args.rs

1//
2// (c) 2019 Alexander Becker
3// Released under the MIT license.
4//
5
6use clap::{Arg, App};
7use log::LogLevelFilter;
8
9pub struct Config {
10    pub threads: usize,
11    pub iface: String,
12    pub log_level: LogLevelFilter,
13    // used for testing
14    pub exit_after: Option<usize>
15}
16
17pub fn get() -> Config {
18    let matches = App::new("yocto: minimalistic in-memory key value store")
19
20        .arg(Arg::with_name("threads")
21            .short("t")
22            .long("threads")
23            .takes_value(true)
24            .help("Number of concurrent threads"))
25
26        .arg(Arg::with_name("iface")
27            .short("i")
28            .long("iface")
29            .takes_value(true)
30            .help("IP address and port, default 127.0.0.1:7001"))
31
32        .arg(Arg::with_name("verbose")
33            .short("v")
34            .long("verbose")
35            .help("Show verbose logs"))
36
37        .get_matches();
38
39    Config {
40        threads: matches.value_of("threads").unwrap_or("4").parse().unwrap(),
41        iface: matches.value_of("iface").unwrap_or("127.0.0.1:7001").to_string(),
42        log_level: if matches.is_present("verbose") {
43            LogLevelFilter::Debug
44        } else {
45            LogLevelFilter::Info
46        },
47        exit_after: None
48    }
49}