From d9b8838a5d99e643a751d042047644cfa4a9a032 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 30 Aug 2020 01:44:25 +0200 Subject: diff_options: Merge `ARG_OPTIONS` and `OPT_OPTIONS` Now that I've confirmed that Git's key value options require an '=' to specify the value, we can drop the distinction between options that require and argument and those that optionally take an argument. Also remove the code that interprets an argument that doesn't start with '-' as the value of the preceding option. --- src/diff_options.rs | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/src/diff_options.rs b/src/diff_options.rs index a35acfd..55b76ce 100644 --- a/src/diff_options.rs +++ b/src/diff_options.rs @@ -76,7 +76,7 @@ static FLAGS: [&'static str; 59] = [ "--ita-invisible-in-index", ]; -static ARG_OPTIONS: [&'static str; 20] = [ +static OPTIONS: [&'static str; 39] = [ "-U", "--unified", "--output", @@ -97,9 +97,6 @@ static ARG_OPTIONS: [&'static str; 20] = [ "--src-prefix", "--dst-prefix", "--line-prefix", -]; - -static OPT_OPTIONS: [&'static str; 19] = [ "--stat", "-X", "--dirstat", @@ -125,24 +122,8 @@ static OPT_OPTIONS: [&'static str; 19] = [ pub fn parse(args: &[String]) -> (Vec<&String>, Vec<&String>) { let mut program_args = Vec::new(); let mut found_args = Vec::new(); - let mut add_next_arg = false; 'args: for arg in args { - let find_arg_prefix = arg.find('-'); - - if add_next_arg - && ( - find_arg_prefix.is_none() - || find_arg_prefix != Some(0) - ) - { - found_args.push(arg); - - add_next_arg = false; - - continue; - } - for flag in FLAGS.iter() { if arg.starts_with(flag) { found_args.push(arg); @@ -151,15 +132,7 @@ pub fn parse(args: &[String]) -> (Vec<&String>, Vec<&String>) { } } - for option in &ARG_OPTIONS { - if arg.starts_with(option) { - found_args.push(arg); - - continue 'args; - } - } - - for option in &OPT_OPTIONS { + for option in OPTIONS.iter() { if arg.starts_with(option) { found_args.push(arg); -- cgit v1.2.3