use clap::ArgMatches;
use failure::Error;
use getset::{Getters, Setters};
use std::convert::TryFrom;
use std::path::PathBuf;
#[derive(Clone, Debug, Default, Getters, Hash, Eq, PartialEq, Setters)]
pub struct Files {
#[get = "pub"]
#[set = "pub"]
path: PathBuf,
}
impl<'a> TryFrom<&'a ArgMatches<'a>> for Files {
type Error = Error;
fn try_from(matches: &'a ArgMatches<'a>) -> Result<Self, Error> {
let files_path = if let Some(files_path) = matches.value_of("files_path") {
PathBuf::from(files_path).join("files")
} else {
PathBuf::from("files")
};
Ok(Self { path: files_path })
}
}
#[cfg(test)]
crate mod test {
use super::Files;
use clap::{App, Arg};
use failure::Error;
use std::convert::TryFrom;
crate fn test_files() -> Result<Files, Error> {
let args = vec!["test", "-f", "files"];
let matches = App::new(env!("CARGO_PKG_NAME"))
.version(env!("CARGO_PKG_VERSION"))
.author(env!("CARGO_PKG_AUTHORS"))
.about("Proxy server for hosting mocked responses on match criteria")
.arg(
Arg::with_name("files_path")
.short("f")
.long("files_path")
.takes_value(true)
.value_name("FILES_PATH"),
)
.get_matches_from(args);
Ok(Files::try_from(&matches)?)
}
}