diff options
author | geemili <minergeemili@gmail.com> | 2016-07-21 17:08:11 -0500 |
---|---|---|
committer | geemili <minergeemili@gmail.com> | 2016-07-21 17:08:11 -0500 |
commit | d60c558cda6fbd9e76bd378710fc035099481f99 (patch) | |
tree | 6e388dd05c16b69c84f3656811e7458ee19a46de /bin | |
parent | d838a5c6b0ef895dc45ea846bd03cbff68bde46e (diff) |
Pulled out lambda and made "--debug" constant
Diffstat (limited to 'bin')
-rw-r--r-- | bin/src/main.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/bin/src/main.rs b/bin/src/main.rs index 4913cd7a..838b132a 100644 --- a/bin/src/main.rs +++ b/bin/src/main.rs @@ -11,6 +11,8 @@ use std::io::ErrorKind; use walkdir::WalkDir; use crossbeam::*; +const DBG_FLAG: &'static str = "--debug"; + fn help(cmds: Vec<String>) { println!(r#" @@ -103,6 +105,10 @@ fn find_flag() -> Option<String> { env::args().skip(1).filter(|x| x.starts_with("-")).next() } +fn is_debug_flag<T: AsRef<str>>(ref s: &T) -> bool { + s.as_ref() == DBG_FLAG +} + fn find_args(command: &str) -> Vec<String> { env::args() .skip(1) @@ -125,7 +131,7 @@ fn main() { }, }, }; - let is_debug = env::args().skip(1).filter(|x| x == "--debug").next().is_some(); + let is_debug = env::args().skip(1).find(is_debug_flag).is_some(); match &first_arg[..] { "--help" | "-h" => { @@ -159,8 +165,8 @@ fn main() { s => { let mut subcommand_args = find_args(s); - if is_debug && subcommand_args.iter().find(|x| *x == "--debug").is_none() { - subcommand_args.push(String::from("--debug")); + if is_debug && subcommand_args.iter().find(is_debug_flag).is_none() { + subcommand_args.push(String::from(DBG_FLAG)); } match Command::new(format!("imag-{}", s)) .stdin(Stdio::inherit()) |