diff --git a/src/cli_args.rs b/src/cli_args.rs index e3b517b..879ea27 100644 --- a/src/cli_args.rs +++ b/src/cli_args.rs @@ -296,18 +296,25 @@ fn die_error(result: Result) -> bool { } fn color(config: &mut AppConfig, args: &mut Peekable>) -> bool { - let arg = args.next().unwrap(); - if let Some(spec) = args.next() { - die_error(parse_color_arg(&spec, config)) + if let Some(spec) = args.peek() { + let parse_result = parse_color_arg(&spec, config); + args.next(); + die_error(parse_result) } else { - missing_arg(arg) + missing_arg(FLAG_COLOR) } } fn line_numbers(config: &mut AppConfig, args: &mut Peekable>) -> bool { - args.next(); - let spec = if let Some(spec) = args.next() { - parse_line_number_style(config, Some(&*spec)) + let maybe_line_number_style = args.peek(); + let spec = if let Some(spec) = maybe_line_number_style { + if spec.starts_with("-") { // next option + parse_line_number_style(config, None) + } else { + let parse_result = parse_line_number_style(config, maybe_line_number_style.map(|s| &s[..])); + args.next(); + parse_result + } } else { parse_line_number_style(config, None) }; @@ -316,13 +323,11 @@ fn line_numbers(config: &mut AppConfig, args: &mut Peekable>) -> bool { config.html = true; - args.next(); true } fn debug(config: &mut AppConfig, args: &mut Peekable>) -> bool { config.debug = true; - args.next(); true } @@ -335,7 +340,7 @@ fn parse_options( config: &mut AppConfig, args: &mut Peekable>, ) -> bool { - if let Some(arg) = args.peek() { + if let Some(arg) = args.next() { match &arg[..] { // generic flags "-h" | "--help" => help(&arg[..] == "--help"), diff --git a/src/tests_cli.rs b/src/tests_cli.rs index b055936..489c5d8 100644 --- a/src/tests_cli.rs +++ b/src/tests_cli.rs @@ -233,6 +233,12 @@ fn line_numbers_style() { err: Empty, is_success: true, }); + test_cli(ProcessTest { + args: &["--line-numbers", "--line-numbers"], + out: Empty, + err: Empty, + is_success: true, + }); // fail test_cli(ProcessTest {