From 8fce010685cf111899483cf11d35752fc446b2c3 Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Mon, 19 Aug 2024 12:15:23 +0200 Subject: [PATCH] 0.3.9 --- Changes | 8 +++ META6.json | 4 +- README.md | 10 ++++ doc/App-Rak.rakudoc | 12 +++++ lib/App/Rak.rakumod | 19 +++++-- resources/help.txt | 2 + resources/help/result.txt | 11 +++++ xt/01-simple.rakutest | 101 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 161 insertions(+), 6 deletions(-) diff --git a/Changes b/Changes index 7caf617..07bc4b2 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,14 @@ Revision history for App-Rak {{$NEXT}} +0.3.9 2024-08-19T12:14:12+02:00 + - Add support for --also-first to produce the first N lines + if there is a match + - Add support for --always-first to always produce the first + N lines, regardless of whether there is a match or not + - Bump dependency on "rak" to get ":also-first" and + ":always-first" support + 0.3.8 2024-08-18T21:09:44+02:00 - Unbreak the --edit-files option: this probably got borked in 0.3.4 . This feature *is* hard to test! diff --git a/META6.json b/META6.json index 8dcd921..9488488 100644 --- a/META6.json +++ b/META6.json @@ -14,7 +14,7 @@ "JSON::Fast::Hyper:ver<0.0.7>:auth", "META::constants:ver<0.0.4>:auth", "Needle::Compile:ver<0.0.7>:auth", - "rak:ver<0.0.60>:auth", + "rak:ver<0.0.61>:auth", "String::Utils:ver<0.0.27+>:auth" ], "description": "21st century grep / find / ack / ag / rg on steroids", @@ -59,5 +59,5 @@ ], "test-depends": [ ], - "version": "0.3.8" + "version": "0.3.9" } diff --git a/README.md b/README.md index 1b6a1bc..cdbdc68 100644 --- a/README.md +++ b/README.md @@ -369,6 +369,16 @@ Only applicable if `--csv-per-line` has been specified. Flag. If specified, indi Only applicable if `--csv-per-line` has been specified. Flag. If specified, indicates that whitespace is allowed around separators. +--also-first[=N] +---------------- + +Indicates the number of lines from the start of the file that should be shown **if** there is a match. If not specified, **0** will be assumed. If specified as a flag, **1** will be assumed. + +--always-first[=N] +------------------ + +Indicates the number of lines from the start of the file that will **always** be shown, regardless of whether there is a match or not. If not specified, **0** will be assumed. If specified as a flag, **1** will be assumed. + --auto-decompress ----------------- diff --git a/doc/App-Rak.rakudoc b/doc/App-Rak.rakudoc index c4fc647..599ad16 100644 --- a/doc/App-Rak.rakudoc +++ b/doc/App-Rak.rakudoc @@ -479,6 +479,18 @@ indicates that fields do not need to be quoted to be acceptable. Only applicable if C<--csv-per-line> has been specified. Flag. If specified, indicates that whitespace is allowed around separators. +=head2 --also-first[=N] + +Indicates the number of lines from the start of the file that should be +shown B there is a match. If not specified, B<0> will be assumed. +If specified as a flag, B<1> will be assumed. + +=head2 --always-first[=N] + +Indicates the number of lines from the start of the file that will B +be shown, regardless of whether there is a match or not. If not specified, +B<0> will be assumed. If specified as a flag, B<1> will be assumed. + =head2 --auto-decompress Flag. If specified with a True value, will accept compressed files diff --git a/lib/App/Rak.rakumod b/lib/App/Rak.rakumod index 70838a6..8fd91f8 100644 --- a/lib/App/Rak.rakumod +++ b/lib/App/Rak.rakumod @@ -3,7 +3,7 @@ use as-cli-arguments:ver<0.0.8>:auth; # as-cli-arguments use IO::Path::AutoDecompress:ver<0.0.3>:auth; # IOAD use JSON::Fast::Hyper:ver<0.0.7>:auth; # from-json to-json use META::constants:ver<0.0.4>:auth $?DISTRIBUTION; -use rak:ver<0.0.60>:auth; # rak Rak +use rak:ver<0.0.61>:auth; # rak Rak use Backtrace::Files:ver<0.0.4>:auth < backtrace-files @@ -31,9 +31,9 @@ my constant BON = "\e[1m"; # BOLD ON my constant BOFF = "\e[22m"; # BOLD OFF #- start of available options -------------------------------------------------- -#- Generated on 2024-08-17T22:09:15+02:00 by tools/makeOPTIONS.raku +#- Generated on 2024-08-19T10:46:24+02:00 by tools/makeOPTIONS.raku #- PLEASE DON'T CHANGE ANYTHING BELOW THIS LINE -my str @options = ; +my str @options = ; #- PLEASE DON'T CHANGE ANYTHING ABOVE THIS LINE #- end of available options ---------------------------------------------------- @@ -975,7 +975,10 @@ my sub show-results(--> Nil) { last RESULT if ++$seen == $stop-after; } } - } + + # in case of --always-first without matches + ++$seen; + } } # looks like frequencies output @@ -1431,6 +1434,14 @@ my sub option-allow-whitespace($value --> Nil) { set-csv-flag('allow-whitespace', $value); } +my sub option-also-first($value --> Nil) { + set-result-flag-or-Int('also-first', $value); +} + +my sub option-always-first($value --> Nil) { + set-result-flag-or-Int('always-first', $value); +} + my sub option-and($value --> Nil) { set-additional-pattern('and', $value, '&'); } diff --git a/resources/help.txt b/resources/help.txt index a9f75bc..d43185b 100644 --- a/resources/help.txt +++ b/resources/help.txt @@ -122,6 +122,8 @@ Filesystem filters: --uid=condition File is owned by given uid Result modifiers: + --also-first=N List first N lines if there is a match + --always-first=N List first N lines always --context=N List N lines around any line with a match --before-context=N List N lines before any line with a match --after-context=N List N lines after any line with a match diff --git a/resources/help/result.txt b/resources/help/result.txt index 8603cf3..60a438f 100644 --- a/resources/help/result.txt +++ b/resources/help/result.txt @@ -9,6 +9,17 @@ Many combinations of these options may or may not make sense. Also produce N items after any item with a match. Defaults to *no* items after any item with a match. +--also-first=N + +Also produce the first N items if there is an item with a match. +Defaults to *no* items. Assumes 1 if specified as a flag. + +--always-first=N + +Always produce the first N items regardles of whether there is an +item with a match. Defaults to *no* items. Assumes 1 if specified as +a flag. + --before-context=N Also produce N items before any item with a match. Defaults to *no* diff --git a/xt/01-simple.rakutest b/xt/01-simple.rakutest index 65267f6..ba291df 100644 --- a/xt/01-simple.rakutest +++ b/xt/01-simple.rakutest @@ -877,6 +877,107 @@ query-ok , ok => qq:to/OK/; 17 unique occurrences in 10 files OK +query-ok , :!head, ok => qq:to/OK/; +eight +1:zero +9:{BON}eight{BOFF} + +nine +1:zero +9:{BON}eight{BOFF} +OK + +query-ok , :!head, ok => qq:to/OK/; +eight +1:zero +2:one +3:two +9:{BON}eight{BOFF} + +nine +1:zero +2:one +3:two +9:{BON}eight{BOFF} +OK + +query-ok , :!head, ok => qq:to/OK/; +zero +1:zero + +one +1:zero + +two +1:zero + +three +1:zero + +four +1:zero + +five +1:zero + +six +1:zero + +seven +1:zero + +eight +1:zero +9:{BON}eight{BOFF} + +nine +1:zero +9:{BON}eight{BOFF} +OK + +query-ok , :!head, ok => qq:to/OK/; +zero +1:zero + +one +1:zero +2:one + +two +1:zero +2:one + +three +1:zero +2:one + +four +1:zero +2:one + +five +1:zero +2:one + +six +1:zero +2:one + +seven +1:zero +2:one + +eight +1:zero +2:one +9:{BON}eight{BOFF} + +nine +1:zero +2:one +9:{BON}eight{BOFF} +OK + done-testing; # vim: expandtab shiftwidth=4