extern crate clap; use clap::{App, ArgMatches}; use std::fmt::Debug; use std::fmt::Formatter; use std::fmt::Error; pub struct ModuleConfig { pub load : bool, } impl ModuleConfig { pub fn new() -> ModuleConfig { ModuleConfig { load: false, } } } pub struct CliConfig<'a> { pub module_configs : Vec, pub cli_matches : ArgMatches<'a, 'a>, } impl<'a> CliConfig<'a> { pub fn new(app : clap::App<'a, 'a, 'a, 'a, 'a, 'a>) -> CliConfig<'a> { CliConfig { module_configs: vec![], cli_matches: app.get_matches(), } } pub fn is_verbose(&self) -> bool { self.cli_matches.is_present("verbose") || self.is_debugging() } pub fn is_debugging(&self) -> bool { self.cli_matches.is_present("debug") } pub fn get_rtp(&self) -> Option { self.cli_matches.value_of("rtp").and_then(|s| Some(String::from(s))) } } impl<'a> Debug for CliConfig<'a> { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { write!(f, "CliConfig (verbose: {}, debugging: {}, rtp: {})", self.is_verbose(), self.is_debugging(), self.get_rtp().or(Some(String::from("NONE"))).unwrap()) } }