Skip to content

Commit

Permalink
replace: add --not-one flag
Browse files Browse the repository at this point in the history
  • Loading branch information
rzmk committed Nov 22, 2024
1 parent e788aff commit c805516
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/cmd/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -36,12 +36,13 @@ replace options:
will match all unicode word characters instead of only
ASCII word characters. Decreases performance.
--size-limit <mb> 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 <mb> 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
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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());
}

Expand Down

0 comments on commit c805516

Please sign in to comment.