Format with rustfmt

This commit is contained in:
Jake Howard 2017-07-18 14:27:50 +01:00
parent 6b94a298c0
commit 37566249a7
Signed by: jake
GPG key ID: 57AFB45680EDD477
6 changed files with 38 additions and 38 deletions

View file

@ -4,7 +4,7 @@ use clap::{App, AppSettings, ArgMatches, Arg, SubCommand};
use clap::Result;
fn get_build_command() -> App<'static, 'static> {
return SubCommand::with_name("build")
return SubCommand::with_name("build");
}
fn build() -> App<'static, 'static> {
@ -16,7 +16,8 @@ fn build() -> App<'static, 'static> {
.global_setting(AppSettings::VersionlessSubcommands)
.global_setting(AppSettings::ColoredHelp)
.global_setting(AppSettings::StrictUtf8)
.arg(Arg::with_name("verbose")
.arg(
Arg::with_name("verbose")
.global(true)
.short("v")
.long("verbose")

View file

@ -8,8 +8,7 @@ pub mod consts;
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct Config {
input: Vec<PathBuf>,
input: Vec<PathBuf>
}
impl Config {

View file

@ -25,5 +25,8 @@ pub fn read() -> String {
pub fn get_input_files(conf: &Value) -> Vec<PathBuf> {
let working_dir = current_dir().unwrap();
let input_values = conf.get("input").unwrap().as_sequence().unwrap().to_vec();
return input_values.into_iter().map(|x| working_dir.join(x.as_str().unwrap().to_string())).collect();
return input_values
.into_iter()
.map(|x| working_dir.join(x.as_str().unwrap().to_string()))
.collect();
}

View file

@ -7,11 +7,7 @@ use config::read;
fn check_required_keys(config: &Value) -> ValidationResult {
for key in vec!(
"input",
"output",
"title"
).iter() {
for key in vec!["input", "output", "title"].iter() {
if config.get(key).is_none() {
return Err(format!("Missing required key {}.", key));
}
@ -30,7 +26,10 @@ fn check_input_files(config: &Value) -> ValidationResult {
}
pub fn unwrap_group(config: &Value, funcs: Vec<&Fn(&Value) -> ValidationResult>) -> ValidationResult {
pub fn unwrap_group(
config: &Value,
funcs: Vec<&Fn(&Value) -> ValidationResult>,
) -> ValidationResult {
for func in funcs.iter() {
let func_result = func(config);
if func_result.is_err() {
@ -42,8 +41,5 @@ pub fn unwrap_group(config: &Value, funcs: Vec<&Fn(&Value) -> ValidationResult>)
pub fn validate(config: &Value) -> ValidationResult {
return unwrap_group(config, vec!(
&check_required_keys,
&check_input_files
));
return unwrap_group(config, vec![&check_required_keys, &check_input_files]);
}

View file

@ -1,5 +1,7 @@
#[macro_use] extern crate clap;
#[macro_use] extern crate serde_derive;
#[macro_use]
extern crate clap;
#[macro_use]
extern crate serde_derive;
extern crate serde_yaml;
@ -16,4 +18,3 @@ fn main() {
println!("{:?}", config::get_config());
}
}

View file

@ -4,11 +4,11 @@ use clap::ErrorKind;
#[test]
fn incorrect_subcommand() {
let out = args::get_matches_for(vec!("mdp"));
let out = args::get_matches_for(vec!["mdp"]);
assert!(out.is_err());
assert_eq!(out.unwrap_err().kind, ErrorKind::MissingArgumentOrSubcommand);
let out = args::get_matches_for(vec!("mdp", "invalid"));
let out = args::get_matches_for(vec!["mdp", "invalid"]);
assert!(out.is_err());
assert_eq!(out.unwrap_err().kind, ErrorKind::UnknownArgument);
}
@ -19,20 +19,20 @@ fn verbose_number() {
return args::get_verbose(args::get_matches_for(arg_list).unwrap());
}
assert_eq!(get_verbose_level(vec!("mdp", "build", "-v")), 1);
assert_eq!(get_verbose_level(vec!("mdp", "build", "-vv")), 2);
assert_eq!(get_verbose_level(vec!("mdp", "-v", "build", "-vv")), 3);
assert_eq!(get_verbose_level(vec!("mdp", "-vv", "build", "-v")), 3);
assert_eq!(get_verbose_level(vec!("mdp", "-v", "build", "-v")), 2);
assert_eq!(get_verbose_level(vec!("mdp", "-v", "build")), 1);
assert_eq!(get_verbose_level(vec!("mdp", "--verbose", "build", "-v")), 2);
assert_eq!(get_verbose_level(vec!("mdp", "-v", "build", "--verbose")), 2);
assert_eq!(get_verbose_level(vec!["mdp", "build", "-v"]), 1);
assert_eq!(get_verbose_level(vec!["mdp", "build", "-vv"]), 2);
assert_eq!(get_verbose_level(vec!["mdp", "-v", "build", "-vv"]), 3);
assert_eq!(get_verbose_level(vec!["mdp", "-vv", "build", "-v"]), 3);
assert_eq!(get_verbose_level(vec!["mdp", "-v", "build", "-v"]), 2);
assert_eq!(get_verbose_level(vec!["mdp", "-v", "build"]), 1);
assert_eq!(get_verbose_level(vec!["mdp", "--verbose", "build", "-v"]), 2);
assert_eq!(get_verbose_level(vec!["mdp", "-v", "build", "--verbose"]), 2);
}
#[test]
fn build_subcommand() {
let out = args::get_matches_for(vec!("mdp", "build"));
let out = args::get_matches_for(vec!["mdp", "build"]);
assert!(out.is_ok());
assert_eq!(out.unwrap().subcommand_name().unwrap(), "build");
}
@ -40,11 +40,11 @@ fn build_subcommand() {
#[test]
fn version_string() {
let out = args::get_matches_for(vec!("mdp", "--version"));
let out = args::get_matches_for(vec!["mdp", "--version"]);
assert!(out.is_err());
assert_eq!(out.unwrap_err().kind, ErrorKind::VersionDisplayed);
let out = args::get_matches_for(vec!("mdp", "build", "--version"));
let out = args::get_matches_for(vec!["mdp", "build", "--version"]);
assert!(out.is_err());
assert_eq!(out.unwrap_err().kind, ErrorKind::UnknownArgument);
}