From f3cb4143890f870b493d84557e9c36440b10ab45 Mon Sep 17 00:00:00 2001 From: rhysd Date: Thu, 4 Apr 2024 18:43:09 +0900 Subject: [PATCH] allow command line arguments to override previous values this is useful when some default options are set in `HGREP_DEFAULT_OPTS` and user wants to change them by subsequent arguments in command line --- CONTRIBUTING.md | 2 +- src/main.rs | 5 + ..._tests__arg_matches__override_options.snap | 204 ++++++++++++++++++ 3 files changed, 210 insertions(+), 1 deletion(-) create mode 100644 testdata/snapshots/hgrep__tests__arg_matches__override_options.snap diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b1f8f12..febba5e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -56,7 +56,7 @@ Once some of them fail, the error messages contain the differences. You need to ```sh # Run snapshot tests -cargo test +cargo insta test # Review snapshot diffs cargo insta review # After accepting the diffs, remember to add the changes diff --git a/src/main.rs b/src/main.rs index f7c45ef..5df324f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -87,6 +87,7 @@ fn command() -> Command { For more details, visit https://github.com/rhysd/hgrep#readme" ) .no_binary_name(true) + .args_override_self(true) .arg( Arg::new("min-context") .short('c') @@ -916,6 +917,10 @@ mod tests { "--list-themes", ] ); + snapshot_test!( + override_options, + ["--theme", "ayu-dark", "--theme", "OneHalfDark"] + ); macro_rules! snapshot_error_test { ($name:ident, $args:expr) => { diff --git a/testdata/snapshots/hgrep__tests__arg_matches__override_options.snap b/testdata/snapshots/hgrep__tests__arg_matches__override_options.snap new file mode 100644 index 0000000..03e8e51 --- /dev/null +++ b/testdata/snapshots/hgrep__tests__arg_matches__override_options.snap @@ -0,0 +1,204 @@ +--- +source: src/main.rs +expression: raw +--- +[ + ( + "ascii-lines", + [ + "false", + ], + ), + ( + "background", + [ + "false", + ], + ), + ( + "crlf", + [ + "false", + ], + ), + ( + "custom-assets", + [ + "false", + ], + ), + ( + "first-only", + [ + "false", + ], + ), + ( + "fixed-strings", + [ + "false", + ], + ), + ( + "follow-symlink", + [ + "false", + ], + ), + ( + "generate-man-page", + [ + "false", + ], + ), + ( + "glob-case-insensitive", + [ + "false", + ], + ), + ( + "grid", + [ + "false", + ], + ), + ( + "hidden", + [ + "false", + ], + ), + ( + "ignore-case", + [ + "false", + ], + ), + ( + "invert-match", + [ + "false", + ], + ), + ( + "line-regexp", + [ + "false", + ], + ), + ( + "list-themes", + [ + "false", + ], + ), + ( + "max-context", + [ + "6", + ], + ), + ( + "min-context", + [ + "3", + ], + ), + ( + "mmap", + [ + "false", + ], + ), + ( + "multiline", + [ + "false", + ], + ), + ( + "multiline-dotall", + [ + "false", + ], + ), + ( + "no-grid", + [ + "false", + ], + ), + ( + "no-ignore", + [ + "false", + ], + ), + ( + "no-unicode", + [ + "false", + ], + ), + ( + "one-file-system", + [ + "false", + ], + ), + ( + "pcre2", + [ + "false", + ], + ), + ( + "printer", + [ + "syntect", + ], + ), + ( + "smart-case", + [ + "false", + ], + ), + ( + "tab", + [ + "4", + ], + ), + ( + "theme", + [ + "OneHalfDark", + ], + ), + ( + "type-list", + [ + "false", + ], + ), + ( + "unrestricted", + [ + "0", + ], + ), + ( + "word-regexp", + [ + "false", + ], + ), + ( + "wrap", + [ + "char", + ], + ), +]