Skip to content

Commit

Permalink
0.3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Aug 19, 2024
1 parent 1ed95f1 commit 8fce010
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 6 deletions.
8 changes: 8 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
4 changes: 2 additions & 2 deletions META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"JSON::Fast::Hyper:ver<0.0.7>:auth<zef:lizmat>",
"META::constants:ver<0.0.4>:auth<zef:lizmat>",
"Needle::Compile:ver<0.0.7>:auth<zef:lizmat>",
"rak:ver<0.0.60>:auth<zef:lizmat>",
"rak:ver<0.0.61>:auth<zef:lizmat>",
"String::Utils:ver<0.0.27+>:auth<zef:lizmat>"
],
"description": "21st century grep / find / ack / ag / rg on steroids",
Expand Down Expand Up @@ -59,5 +59,5 @@
],
"test-depends": [
],
"version": "0.3.8"
"version": "0.3.9"
}
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------------

Expand Down
12 changes: 12 additions & 0 deletions doc/App-Rak.rakudoc
Original file line number Diff line number Diff line change
Expand Up @@ -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<if> 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<always>
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
Expand Down
19 changes: 15 additions & 4 deletions lib/App/Rak.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use as-cli-arguments:ver<0.0.8>:auth<zef:lizmat>; # as-cli-arguments
use IO::Path::AutoDecompress:ver<0.0.3>:auth<zef:lizmat>; # IOAD
use JSON::Fast::Hyper:ver<0.0.7>:auth<zef:lizmat>; # from-json to-json
use META::constants:ver<0.0.4>:auth<zef:lizmat> $?DISTRIBUTION;
use rak:ver<0.0.60>:auth<zef:lizmat>; # rak Rak
use rak:ver<0.0.61>:auth<zef:lizmat>; # rak Rak

use Backtrace::Files:ver<0.0.4>:auth<zef:lizmat> <
backtrace-files
Expand Down Expand Up @@ -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 = <absolute accept accessed ack after-context allow-loose-escapes allow-loose-quotes allow-whitespace and andnot auto-decompress auto-diag backtrace backup batch before-context blame-per-file blame-per-line blocks break checkout classify categorize context count-only created csv-per-line degree deny description device-number dir dont-catch dryrun ecosystem edit encoding eol escape exec execute-raku extensions file file-separator-null files-from files-with-matches files-without-matches filesize find formula frequencies gid group group-matches hard-links has-setgid has-setuid headers help highlight highlight-after highlight-before human ignorecase ignoremark inode invert-match is-empty is-executable is-group-executable is-group-readable is-group-writable is-moarvm is-owned-by-group is-owned-by-user is-owner-executable is-owner-readable is-owner-writable is-pdf is-readable is-sticky is-symbolic-link is-text is-world-executable is-world-readable is-world-writable is-writable json-per-elem json-per-file json-per-line keep-meta list-custom-options list-expanded-options list-known-extensions matches-only max-matches-per-file mbc mbc-frames mbc-strings meta-modified mode modified modify-files module not only-first or ornot output-dir output-file pager paragraph-context passthru passthru-context paths paths-from pattern patterns-from pdf-info pdf-per-file pdf-per-line per-file per-line per-paragraph progress proximate rename-files quietly quote rak recurse-symlinked-dir recurse-unmatched-dir repository save sayer sep shell show-blame show-filename show-item-number silently smartcase smartmark sourcery stats stats-only strict summary-if-larger-than trim type uid under-version-control unicode unique user verbose version vimgrep with-line-endings>;
my str @options = <absolute accept accessed ack after-context allow-loose-escapes allow-loose-quotes allow-whitespace also-first always-first and andnot auto-decompress auto-diag backtrace backup batch before-context blame-per-file blame-per-line blocks break checkout classify categorize context count-only created csv-per-line degree deny description device-number dir dont-catch dryrun ecosystem edit encoding eol escape exec execute-raku extensions file file-separator-null files-from files-with-matches files-without-matches filesize find formula frequencies gid group group-matches hard-links has-setgid has-setuid headers help highlight highlight-after highlight-before human ignorecase ignoremark inode invert-match is-empty is-executable is-group-executable is-group-readable is-group-writable is-moarvm is-owned-by-group is-owned-by-user is-owner-executable is-owner-readable is-owner-writable is-pdf is-readable is-sticky is-symbolic-link is-text is-world-executable is-world-readable is-world-writable is-writable json-per-elem json-per-file json-per-line keep-meta list-custom-options list-expanded-options list-known-extensions matches-only max-matches-per-file mbc mbc-frames mbc-strings meta-modified mode modified modify-files module not only-first or ornot output-dir output-file pager paragraph-context passthru passthru-context paths paths-from pattern patterns-from pdf-info pdf-per-file pdf-per-line per-file per-line per-paragraph progress proximate rename-files quietly quote rak recurse-symlinked-dir recurse-unmatched-dir repository save sayer sep shell show-blame show-filename show-item-number silently smartcase smartmark sourcery stats stats-only strict summary-if-larger-than trim type uid under-version-control unicode unique user verbose version vimgrep with-line-endings>;
#- PLEASE DON'T CHANGE ANYTHING ABOVE THIS LINE
#- end of available options ----------------------------------------------------

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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, '&');
}
Expand Down
2 changes: 2 additions & 0 deletions resources/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions resources/help/result.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
101 changes: 101 additions & 0 deletions xt/01-simple.rakutest
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,107 @@ query-ok </./ --unique --count-only --matches-only --verbose>, ok => qq:to/OK/;
17 unique occurrences in 10 files
OK

query-ok <eight --also-first>, :!head, ok => qq:to/OK/;
eight
1:zero
9:{BON}eight{BOFF}

nine
1:zero
9:{BON}eight{BOFF}
OK

query-ok <eight --also-first=3>, :!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 <eight --always-first>, :!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 <eight --always-first=2>, :!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

0 comments on commit 8fce010

Please sign in to comment.