Skip to content

Commit

Permalink
fix the mistake of overriding mode
Browse files Browse the repository at this point in the history
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(_))
  • Loading branch information
QWZeng committed Sep 4, 2024
1 parent ea99421 commit 10c09e0
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 75 deletions.
139 changes: 70 additions & 69 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions crates/core/flags/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/core/flags/lowargs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 10c09e0

Please sign in to comment.