2015-12-05 00:14:13 +00:00
|
|
|
use std::fmt::{Debug, Formatter, Error};
|
|
|
|
|
2015-10-18 13:58:17 +00:00
|
|
|
extern crate clap;
|
|
|
|
use clap::{App, ArgMatches};
|
|
|
|
|
|
|
|
pub struct ModuleConfig {
|
2015-10-18 18:52:35 +00:00
|
|
|
pub load : bool,
|
2015-10-18 13:58:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ModuleConfig {
|
|
|
|
pub fn new() -> ModuleConfig {
|
|
|
|
ModuleConfig {
|
|
|
|
load: false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-26 23:02:42 +00:00
|
|
|
pub struct CliConfig<'a> {
|
2015-10-18 18:52:35 +00:00
|
|
|
pub module_configs : Vec<ModuleConfig>,
|
2015-10-25 18:47:17 +00:00
|
|
|
pub cli_matches : ArgMatches<'a, 'a>,
|
2015-10-18 13:58:17 +00:00
|
|
|
}
|
|
|
|
|
2015-10-26 23:02:42 +00:00
|
|
|
impl<'a> CliConfig<'a> {
|
|
|
|
pub fn new(app : clap::App<'a, 'a, 'a, 'a, 'a, 'a>) -> CliConfig<'a> {
|
|
|
|
CliConfig {
|
2015-10-18 13:58:17 +00:00
|
|
|
module_configs: vec![],
|
2015-10-25 18:47:17 +00:00
|
|
|
cli_matches: app.get_matches(),
|
2015-10-18 13:58:17 +00:00
|
|
|
}
|
|
|
|
}
|
2015-10-18 18:52:35 +00:00
|
|
|
|
2015-12-29 15:45:14 +00:00
|
|
|
/**
|
|
|
|
* Check whether the CLI says we should run verbose
|
|
|
|
*/
|
2015-10-18 18:52:35 +00:00
|
|
|
pub fn is_verbose(&self) -> bool {
|
2015-10-26 20:26:15 +00:00
|
|
|
self.cli_matches.is_present("verbose") || self.is_debugging()
|
2015-10-18 18:52:35 +00:00
|
|
|
}
|
|
|
|
|
2015-12-29 15:45:14 +00:00
|
|
|
/**
|
|
|
|
* Check whether the CLI says we should run in debugging
|
|
|
|
*/
|
2015-10-18 18:52:35 +00:00
|
|
|
pub fn is_debugging(&self) -> bool {
|
2015-10-26 20:26:15 +00:00
|
|
|
self.cli_matches.is_present("debug")
|
2015-10-18 13:58:17 +00:00
|
|
|
}
|
2015-11-23 18:48:33 +00:00
|
|
|
|
2015-12-29 15:45:14 +00:00
|
|
|
/**
|
|
|
|
* Get the runtime path the CLI configured
|
|
|
|
*/
|
2015-11-23 18:48:33 +00:00
|
|
|
pub fn get_rtp(&self) -> Option<String> {
|
|
|
|
self.cli_matches.value_of("rtp").and_then(|s| Some(String::from(s)))
|
|
|
|
}
|
2015-12-01 17:37:29 +00:00
|
|
|
|
2015-12-29 15:45:14 +00:00
|
|
|
/**
|
|
|
|
* Get the store path the CLI configured
|
|
|
|
*
|
|
|
|
* TODO: Implement properly. Not working by now.
|
|
|
|
*/
|
2015-12-01 17:37:29 +00:00
|
|
|
pub fn store_path(&self) -> Option<String> {
|
|
|
|
self.get_rtp().and_then(|rtp| {
|
|
|
|
self.cli_matches
|
|
|
|
.value_of("storepath")
|
|
|
|
.and_then(|s| Some(rtp + s))
|
|
|
|
})
|
|
|
|
}
|
2015-12-30 01:40:56 +00:00
|
|
|
|
|
|
|
pub fn editor(&self) -> Option<String> {
|
|
|
|
self.cli_matches.value_of("editor").and_then(|s| Some(String::from(s)))
|
|
|
|
}
|
2015-12-30 01:42:55 +00:00
|
|
|
|
|
|
|
pub fn editor_opts(&self) -> String {
|
|
|
|
self.cli_matches
|
|
|
|
.value_of("editor_opts")
|
|
|
|
.map(|s| String::from(s))
|
|
|
|
.unwrap_or(String::from(""))
|
|
|
|
}
|
2015-10-18 13:58:17 +00:00
|
|
|
}
|
|
|
|
|
2015-11-27 18:18:38 +00:00
|
|
|
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())
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|