Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the mistake of overriding mode #2880

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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