Skip to content

Commit

Permalink
0.2.24
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed May 13, 2024
1 parent aa73d47 commit ecc029d
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 60 deletions.
18 changes: 18 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
Revision history for App-Rak

{{$NEXT}}

0.2.24 2024-05-13T15:50:05+02:00
- Allow --edit to work with --files-with-matches and
--files-without-matches
- Add support for --mbc option to allow searches on the
structure of a MoarVM bytecode file
- Upped dependency on "rak" to follow renaming of the
":sort" argument to ":sort-sources", for ":progress"
support and several race condition fixes and general
improvements
- Alert to possible erroneous path specification if not
a single source file was found
- Add support for --progress option, writing search result
progress to STDERR
- The --unique option will now sort the result using
foldcase logic
- Update help on --only-first: the default is 1000, not 1
- Stats output is now done on STDERR instead of STDOUT,
as it's not really part of the result
- Update copyright year

0.2.23 2024-05-09T13:51:24+02:00
- Upped dependency on "rak" to fix issue with readability of
Expand Down
6 changes: 3 additions & 3 deletions META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"IO::Path::AutoDecompress:ver<0.0.2>:auth<zef:lizmat>",
"JSON::Fast::Hyper:ver<0.0.5>:auth<zef:lizmat>",
"META::constants:ver<0.0.3>:auth<zef:lizmat>",
"rak:ver<0.0.52>:auth<zef:lizmat>",
"String::Utils:ver<0.0.22+>:auth<zef:lizmat>"
"rak:ver<0.0.53>:auth<zef:lizmat>",
"String::Utils:ver<0.0.23+>:auth<zef:lizmat>"
],
"description": "21st century grep / find / ack / ag / rg on steroids",
"license": "Artistic-2.0",
Expand Down Expand Up @@ -59,5 +59,5 @@
],
"test-depends": [
],
"version": "0.2.23"
"version": "0.2.24"
}
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1176,10 +1176,17 @@ Flag. Indicate whether only the matched pattern should be produced, rather than

Indicate the maximum number of matches that should be produced per file. If specified as a flag, will assume **1** for its value. By default, will produce **all** possible matches in a file.

--mbc
-----

Flag. Indicates that a [`MoarVM::Bytecode`](https://raku.land/zef:lizmat/MoarVM::Bytecode) object should be produced for each MoarVM bytecode file, to be presented to the matcher. Only makes sense if the pattern is a `Callable`. Will also set the `is-moarvm` flag to only select MoarVM bytecode files, unless reading from STDIN.

Requires the [`MoarVM::Bytecode`](https://raku.land/zef:lizmat/MoarVM::Bytecode) Raku module to be installed.

--mbc-frames
------------

Flag. Indicates that the frames in a MoarVM bytecode file should be produced as a [`MoarVM::Bytecode::Frame`ihttps://raku.land/zef:lizmat/MoarVM::Bytecode#frame](`MoarVM::Bytecode::Frame`ihttps://raku.land/zef:lizmat/MoarVM::Bytecode#frame) to the matcher. Only makes sense if the pattern is a `Callable`. Will also set the `is-moarvm` flag to only select MoarVM bytecode files, unless reading from STDIN.
Flag. Indicates that the frames in a MoarVM bytecode file should be produced as a [`MoarVM::Bytecode::Frame`](https://raku.land/zef:lizmat/MoarVM::Bytecode#frame) to the matcher. Only makes sense if the pattern is a `Callable`. Will also set the `is-moarvm` flag to only select MoarVM bytecode files, unless reading from STDIN.

Requires the [`MoarVM::Bytecode`](https://raku.land/zef:lizmat/MoarVM::Bytecode) Raku module to be installed.

Expand Down Expand Up @@ -1367,6 +1374,11 @@ Optionally takes a `Callable` specification: this will be given an `IO::Path` ob
$ rak foo --per-line='*.lines.tail(10)'
```

--progress
----------

Flag. If specified, will produce a progress indicator on STDERR that indicates the number of files checked, number of lines checked and number of matches, updated 5 times per second. Defaults to `False`.

--proximate=[N]
---------------

Expand Down Expand Up @@ -1726,7 +1738,7 @@ If you like this module, or what I’m doing more generally, committing to a [sm
COPYRIGHT AND LICENSE
=====================

Copyright 2022, 2023 Elizabeth Mattijsen
Copyright 2022, 2023, 2024 Elizabeth Mattijsen

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.

21 changes: 19 additions & 2 deletions doc/App-Rak.rakudoc
Original file line number Diff line number Diff line change
Expand Up @@ -1491,10 +1491,21 @@ Indicate the maximum number of matches that should be produced per file.
If specified as a flag, will assume B<1> for its value. By default, will
produce B<all> possible matches in a file.

=head2 --mbc

Flag. Indicates that a L<C<MoarVM::Bytecode>|https://raku.land/zef:lizmat/MoarVM::Bytecode>
object should be produced for each MoarVM bytecode file, to be presented
to the matcher. Only makes sense if the pattern is a C<Callable>. Will
also set the C<is-moarvm> flag to only select MoarVM bytecode files,
unless reading from STDIN.

Requires the L<C<MoarVM::Bytecode>|https://raku.land/zef:lizmat/MoarVM::Bytecode>
Raku module to be installed.

=head2 --mbc-frames

Flag. Indicates that the frames in a MoarVM bytecode file should be
produced as a L<C<MoarVM::Bytecode::Frame>ihttps://raku.land/zef:lizmat/MoarVM::Bytecode#frame>
produced as a L<C<MoarVM::Bytecode::Frame>|https://raku.land/zef:lizmat/MoarVM::Bytecode#frame>
to the matcher. Only makes sense if the pattern is a C<Callable>. Will
also set the C<is-moarvm> flag to only select MoarVM bytecode files,
unless reading from STDIN.
Expand Down Expand Up @@ -1742,6 +1753,12 @@ $ rak foo --per-line='*.lines.tail(10)'

=end code

=head2 --progress

Flag. If specified, will produce a progress indicator on STDERR that
indicates the number of files checked, number of lines checked and number
of matches, updated 5 times per second. Defaults to C<False>.

=head2 --proximate=[N]

Indicates whether matched lines should be grouped together that are within
Expand Down Expand Up @@ -2203,7 +2220,7 @@ deal to me!

=head1 COPYRIGHT AND LICENSE

Copyright 2022, 2023 Elizabeth Mattijsen
Copyright 2022, 2023, 2024 Elizabeth Mattijsen

This library is free software; you can redistribute it and/or modify it under
the Artistic License 2.0.
Expand Down
77 changes: 58 additions & 19 deletions lib/App/Rak.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use highlighter:ver<0.0.18>:auth<zef:lizmat>; # columns highlighter matches Type
use IO::Path::AutoDecompress:ver<0.0.2>:auth<zef:lizmat>; # IOAD
use JSON::Fast::Hyper:ver<0.0.5>:auth<zef:lizmat>; # from-json to-json
use META::constants:ver<0.0.3>:auth<zef:lizmat> $?DISTRIBUTION;
use rak:ver<0.0.52>:auth<zef:lizmat>; # rak Rak
use rak:ver<0.0.53>:auth<zef:lizmat>; # rak Rak

use Backtrace::Files:ver<0.0.3>:auth<zef:lizmat> <
backtrace-files
>;
use String::Utils:ver<0.0.22+>:auth<zef:lizmat> <
use String::Utils:ver<0.0.23+>:auth<zef:lizmat> <
after before between is-sha1 non-word has-marks
>;

Expand All @@ -22,9 +22,9 @@ my constant BON = "\e[1m"; # BOLD ON
my constant BOFF = "\e[22m"; # BOLD OFF

#- start of available options --------------------------------------------------
#- Generated on 2024-05-08T19:41:02+02:00 by tools/makeOPTIONS.raku
#- Generated on 2024-05-12T20:26:03+02:00 by tools/makeOPTIONS.raku
#- PLEASE DON'T CHANGE ANYTHING BELOW THIS LINE
my str @options = <absolute accept accessed after-context allow-loose-escapes allow-loose-quotes allow-whitespace 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-frames mbc-strings meta-modified mode modified modify-files module only-first 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 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 after-context allow-loose-escapes allow-loose-quotes allow-whitespace 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 only-first 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 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 @@ -134,6 +134,7 @@ my sub seconds($format) {
# Make sure we remember if there's a human watching (terminal connected)
my $reading-from-stdin := !$*IN.t;
my $writing-to-stdout := $*OUT.t;
my $writing-to-stderr := $*ERR.t;

# Set up default extension sets
my constant %exts =
Expand Down Expand Up @@ -1140,10 +1141,14 @@ my sub show-results(--> Nil) {
# Statistics to show
my sub rak-stats(:$count-only --> Nil) {
if $rak.stats -> %s {
# Stop any progress reporting
$rak.stop-progress;
if $rak.stats {
if $count-only && !$verbose {
sayer %s<nr-matches> + %s<nr-changes>
~ " matches in %s<nr-sources> files";
note $rak.nr-matches + $rak.nr-changes
~ " matches in $rak.nr-sources() files";
}
else {
my str @stats;
Expand All @@ -1153,24 +1158,27 @@ my sub rak-stats(:$count-only --> Nil) {
@stats.unshift: $bar;
@stats.push: $bar;
}
@stats.push: " Number of files: %s<nr-sources>";
@stats.push: " Number of files: $rak.nr-sources()";
if %s<nr-items> -> $items {
if $rak.nr-items -> $items {
@stats.push: " Number of lines: $items";
}
if %s<nr-matches> -> $matches {
if $rak.nr-matches -> $matches {
@stats.push: " Number of matches: $matches";
}
if %s<nr-passthrus> -> $passthrus {
if $rak.nr-passthrus -> $passthrus {
@stats.push: "Number of passthrus: $passthrus";
}
if %s<nr-changes> -> $changes {
if $rak.nr-changes -> $changes {
@stats.push: " Number of changes: $changes";
}
sayer @stats.join("\n");
note @stats.join("\n");
}
}
elsif $rak.nr-sources == 0 {
note "Path specification did not select any files, so there was nothing to match.";
}
}
#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -1943,6 +1951,11 @@ my sub option-max-matches-per-file($value --> Nil) {
set-result-flag-or-Int('max-matches-per-file', $value);
}
my sub option-mbc($value --> Nil) {
check-MoarVMBytecode('mbc');
set-action('mbc', $value);
}
my sub option-mbc-frames($value --> Nil) {
check-MoarVMBytecode('mbc-frames');
set-action('mbc-frames', $value);
Expand Down Expand Up @@ -2102,6 +2115,24 @@ my sub option-per-line($value --> Nil) {
!! convert-to-simple-Callable($value, 'per-line');
}
my sub option-progress($value --> Nil) {
my $ERR := PROCESS::<$ERR>;
multi sub progress() { $ERR.print: (" " x 80) ~ "\r" }
multi sub progress($p) {
my $progress := "$p.nr-sources() / $p.nr-items() / $p.nr-matches()";
$ERR.print: (" " x (80 - $progress.chars)) ~ $progress ~ "\r";
}
Bool.ACCEPTS($value)
?? $value
?? $writing-to-stderr
?? (%rak<progress> := &progress)
!! meh "--progress can only write to STDERR"
!! Nil
!! meh "'--progress' must be a flag"
}
my sub option-proximate($value --> Nil) {
set-listing-flag-or-Int('proximate', $value);
}
Expand Down Expand Up @@ -2232,6 +2263,7 @@ my sub option-unicode($value --> Nil) {
my sub option-unique($value --> Nil) {
set-result-flag('unique', $value);
set-rak-flag('sort', True);
}
my sub option-user($value --> Nil) {
Expand Down Expand Up @@ -3041,7 +3073,7 @@ my sub action-modify-files(--> Nil) {
%rak<with-line-endings> := True unless %rak<with-line-endings>:exists;
%rak<passthru-context> := %listing<passthru-context>:delete // True;
%rak<sort> := *.absolute;
%rak<sort-sources> := *.absolute;
%rak<mapper> := -> $io, @matches --> Empty {
++$nr-files-seen;
Expand Down Expand Up @@ -3105,27 +3137,34 @@ my sub action-modify-files(--> Nil) {
rak-stats;
}
my sub handle-mbc(str $what, &handler --> Nil) {
my sub handle-mbc(str $what, str $producer, &handler --> Nil) {
meh-for $what, <modify>;
prepare-needle;
%filesystem<is-moarvm> //= True unless $reading-from-stdin;
move-filesystem-options-to-rak;
move-result-options-to-rak;
%rak<produce-many> := &handler;
%rak{$producer} := &handler;
activate-output-options;
run-rak;
rak-results;
rak-stats;
}
my sub action-mbc(--> Nil) {
handle-mbc 'mbc', 'produce-one',
-> $io { $MoarVMBytecode.new($io) }
}
my sub action-mbc-frames(--> Nil) {
handle-mbc 'mbc-frames', -> $io { $MoarVMBytecode.new($io).frames }
handle-mbc 'mbc-frames', 'produce-many',
-> $io { $MoarVMBytecode.new($io).frames }
}
my sub action-mbc-strings(--> Nil) {
handle-mbc 'mbc-strings', -> $io { $MoarVMBytecode.new($io).strings }
handle-mbc 'mbc-strings', 'produce-many',
-> $io { $MoarVMBytecode.new($io).strings }
}
my sub handle-pdf(str $what, str $producer, &handler --> Nil) {
Expand Down Expand Up @@ -3359,7 +3398,7 @@ my sub action-rename-files(--> Nil) {
%rak<omit-item-number> := True;
%rak<map-all> := True;
%rak<old-new> := True;
%rak<sort> := *.absolute;
%rak<sort-sources> := *.absolute;
%rak<mapper> := -> $, @files --> Empty {
my @existed;
my @done;
Expand Down
4 changes: 3 additions & 1 deletion resources/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Item producers:
--json-per-line Interpret each line as JSON for pattern matching
--blame-per-file Produce Git::Blame::File object for pattern matcing
--blame-per-line Produce Git::Blame::Line objects for pattern matching
--mbc Produce one MoarVM::Bytecode object per file for matching
--mbc-frames Produce MoarVM::Bytecode::Frame objects for matching
--mbc-strings Produce MoarVM::Bytecode string-heap strings for matching
--unicode Produce names of codepoints for pattern matching
Expand Down Expand Up @@ -142,7 +143,7 @@ Listing modifiers:
--highlight-before=xxx String to put before match
--highlight-after=yyy String to put after match
--proximate[=N] Grouping of matched lines
--only-first[=N] Show only the N results, N defaults to 1
--only-first[=N] Only N results, default N = 1, absence = 1000
--output-file=filename Store output to indicated file (default: STDOUT)
--output-dir=directory Store output ino indicated directory / group
--pager Pager to use (default: RAK_PAGER // none)
Expand Down Expand Up @@ -181,6 +182,7 @@ General options:
pattern | philosophy | resource | result | special | string
--help foo Search for "foo" in all help subjects
--help=faq foo Search for "foo" in subject "faq"
--progress Show search progress on STDERR
--version Show version information
--verbose Be more verbose, if applicable

Expand Down
12 changes: 8 additions & 4 deletions resources/help/general.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ logical paragraph of any match.

--help=faq foo

Show information about "foo" in the given subject only, and show the entire
logical paragraph of any match.
Show information about "foo" in the given subject only, and show the
entire logical paragraph of any match.

--progress

Show progress of searching as "nr-files / nr-lines / nr-matches" on
STDERR, updated 5 times per second

--version

Show version information about the "rak" command line interface.

--verbose

If specified with a True value, will show more information if that
is possible, depending on the other arguments.
Show more information if possible, depending on the other arguments.
6 changes: 6 additions & 0 deletions resources/help/item.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ Attempt to interprete file as a PDF file, and by pass its text contents
as lines to the pattern matcher. Only looks at PDF files (as if
--is-pdf has been specified).

--mbc

Attempt to interprete files as a MoarVM bytecode file and pass one
MoarVM::Bytecode object to the pattern matcher for each file. Only looks
at MoarVM bytecode files (as if --is-moarvm has been specified).

--mbc-frames

Attempt to interprete files as a MoarVM bytecode file and pass
Expand Down
4 changes: 2 additions & 2 deletions resources/help/result.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Example:
# categorize by the first two letters of a line
$ rak --categorize='*.substr(0,2).comb'


--classify=classifier

If specified, indicates the Callable that should return a key for a
Expand Down Expand Up @@ -95,4 +94,5 @@ See also --stats.

--unique

Only produce unique items (or whatever a Callable pattern produced).
Only produce unique items (or whatever a Callable pattern produced)
sorted by foldcase logic.
Loading

0 comments on commit ecc029d

Please sign in to comment.