Skip to content

Commit

Permalink
allow command line arguments to override previous values
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rhysd committed Apr 4, 2024
1 parent e91254e commit f3cb414
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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) => {
Expand Down
204 changes: 204 additions & 0 deletions testdata/snapshots/hgrep__tests__arg_matches__override_options.snap

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

0 comments on commit f3cb414

Please sign in to comment.