From c80551690d24a76bf37120a0964fdedb4b42ebef Mon Sep 17 00:00:00 2001 From: rzmk <30333942+rzmk@users.noreply.github.com> Date: Fri, 22 Nov 2024 16:45:22 -0500 Subject: [PATCH] `replace`: add `--not-one` flag --- src/cmd/replace.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cmd/replace.rs b/src/cmd/replace.rs index 59b9a7fb9..0e9851a57 100644 --- a/src/cmd/replace.rs +++ b/src/cmd/replace.rs @@ -9,7 +9,7 @@ backslash or by wrapping the replacement string into single quotes: $ qsv replace "hel(lo)" "hal\$1" file.csv Returns exitcode 0 when replacements are done, returning number of replacements to stderr. -Returns exitcode 1 when no replacements are done. +Returns exitcode 1 when no replacements are done, unless the '--not-one' flag is used. For more examples, see https://github.com/jqnatividad/qsv/blob/master/tests/test_replace.rs. @@ -36,12 +36,13 @@ replace options: will match all unicode word characters instead of only ASCII word characters. Decreases performance. --size-limit Set the approximate size limit (MB) of the compiled - regular expression. If the compiled expression exceeds this + regular expression. If the compiled expression exceeds this number, then a compilation error is returned. [default: 50] --dfa-size-limit Set the approximate size of the cache (MB) used by the regular expression engine's Discrete Finite Automata. [default: 10] + --not-one Use exit code 0 instead of 1 for no match found. Common options: -h, --help Display this message @@ -84,6 +85,7 @@ struct Args { flag_literal: bool, flag_size_limit: usize, flag_dfa_size_limit: usize, + flag_not_one: bool, flag_progressbar: bool, flag_quiet: bool, } @@ -211,7 +213,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> { if !args.flag_quiet { eprintln!("{total_match_ctr}"); } - if total_match_ctr == 0 { + if total_match_ctr == 0 && !args.flag_not_one { return Err(CliError::NoMatch()); }