From d81e6bfbb6b5bf9e943b9c89cc13cc4c3880baa9 Mon Sep 17 00:00:00 2001 From: QWZeng Date: Tue, 3 Sep 2024 18:41:39 +0800 Subject: [PATCH] fix the mistake of overriding mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit a non-searching mode can override non-searching mode. It’s likely just a mistake or typo : if !matches!(*self, Mode::Search(_)); it should be: if !matches!(new, Mode::Search(_)) --- crates/core/flags/defs.rs | 15 ++++++++++----- crates/core/flags/lowargs.rs | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/crates/core/flags/defs.rs b/crates/core/flags/defs.rs index 9a196c491..28ad2f51d 100644 --- a/crates/core/flags/defs.rs +++ b/crates/core/flags/defs.rs @@ -2442,14 +2442,15 @@ fn test_generate() { .unwrap(); assert_eq!(Mode::Generate(GenerateMode::Man), args.mode); - let args = parse_low_raw(["--generate", "man", "-l"]).unwrap(); - assert_eq!(Mode::Search(SearchMode::FilesWithMatches), args.mode); + let args = parse_low_raw(["-l", "--generate", "man",]).unwrap(); + assert_eq!(Mode::Generate(GenerateMode::Man), args.mode); + + let args = parse_low_raw(["--generate", "man", "--files"]).unwrap(); + assert_eq!(Mode::Files, args.mode); - // An interesting quirk of how the modes override each other that lets - // you get back to the "default" mode of searching. let args = parse_low_raw(["--generate", "man", "--json", "--no-json"]).unwrap(); - assert_eq!(Mode::Search(SearchMode::Standard), args.mode); + assert_eq!(Mode::Generate(GenerateMode::Man), args.mode); } /// -g/--glob @@ -5658,6 +5659,10 @@ fn test_quiet() { let args = parse_low_raw(["-q", "--count-matches"]).unwrap(); assert_eq!(true, args.quiet); + + let args = parse_low_raw(["--files", "-l"]).unwrap(); + dbg!(args.mode); + assert_eq!(Mode::Files, args.mode); } /// --regex-size-limit diff --git a/crates/core/flags/lowargs.rs b/crates/core/flags/lowargs.rs index 184c96ae8..f5928351f 100644 --- a/crates/core/flags/lowargs.rs +++ b/crates/core/flags/lowargs.rs @@ -181,7 +181,7 @@ impl Mode { // Once we're in a non-search mode, other non-search modes // can override it. But search modes cannot. So for example, // `--files -l` will still be Mode::Files. - if !matches!(*self, Mode::Search(_)) { + if !matches!(new, Mode::Search(_)) { *self = new; } }