From ecc029dd0be895e185192e6334d89eaab8b420fa Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Mon, 13 May 2024 15:51:33 +0200 Subject: [PATCH] 0.2.24 --- Changes | 18 +++++++++ META6.json | 6 +-- README.md | 16 +++++++- doc/App-Rak.rakudoc | 21 ++++++++++- lib/App/Rak.rakumod | 77 ++++++++++++++++++++++++++++---------- resources/help.txt | 4 +- resources/help/general.txt | 12 ++++-- resources/help/item.txt | 6 +++ resources/help/result.txt | 4 +- xt/01-simple.rakutest | 54 ++++++++++++++------------ xt/05-mbc.rakutest | 6 +-- 11 files changed, 164 insertions(+), 60 deletions(-) diff --git a/Changes b/Changes index 42c4b6f..ccaceb5 100644 --- a/Changes +++ b/Changes @@ -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 diff --git a/META6.json b/META6.json index 952b8ad..ca22da1 100644 --- a/META6.json +++ b/META6.json @@ -14,8 +14,8 @@ "IO::Path::AutoDecompress:ver<0.0.2>:auth", "JSON::Fast::Hyper:ver<0.0.5>:auth", "META::constants:ver<0.0.3>:auth", - "rak:ver<0.0.52>:auth", - "String::Utils:ver<0.0.22+>:auth" + "rak:ver<0.0.53>:auth", + "String::Utils:ver<0.0.23+>:auth" ], "description": "21st century grep / find / ack / ag / rg on steroids", "license": "Artistic-2.0", @@ -59,5 +59,5 @@ ], "test-depends": [ ], - "version": "0.2.23" + "version": "0.2.24" } diff --git a/README.md b/README.md index a442443..0c881fc 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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] --------------- @@ -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. diff --git a/doc/App-Rak.rakudoc b/doc/App-Rak.rakudoc index a8b520a..dc5f65e 100644 --- a/doc/App-Rak.rakudoc +++ b/doc/App-Rak.rakudoc @@ -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 possible matches in a file. +=head2 --mbc + +Flag. Indicates that a L|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. Will +also set the C flag to only select MoarVM bytecode files, +unless reading from STDIN. + +Requires the L|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 Lihttps://raku.land/zef:lizmat/MoarVM::Bytecode#frame> +produced as a L|https://raku.land/zef:lizmat/MoarVM::Bytecode#frame> to the matcher. Only makes sense if the pattern is a C. Will also set the C flag to only select MoarVM bytecode files, unless reading from STDIN. @@ -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. + =head2 --proximate=[N] Indicates whether matched lines should be grouped together that are within @@ -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. diff --git a/lib/App/Rak.rakumod b/lib/App/Rak.rakumod index 36f8d35..86df5c7 100644 --- a/lib/App/Rak.rakumod +++ b/lib/App/Rak.rakumod @@ -5,12 +5,12 @@ use highlighter:ver<0.0.18>:auth; # columns highlighter matches Type use IO::Path::AutoDecompress:ver<0.0.2>:auth; # IOAD use JSON::Fast::Hyper:ver<0.0.5>:auth; # from-json to-json use META::constants:ver<0.0.3>:auth $?DISTRIBUTION; -use rak:ver<0.0.52>:auth; # rak Rak +use rak:ver<0.0.53>:auth; # rak Rak use Backtrace::Files:ver<0.0.3>:auth < backtrace-files >; -use String::Utils:ver<0.0.22+>:auth < +use String::Utils:ver<0.0.23+>:auth < after before between is-sha1 non-word has-marks >; @@ -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 = ; +my str @options = ; #- PLEASE DON'T CHANGE ANYTHING ABOVE THIS LINE #- end of available options ---------------------------------------------------- @@ -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 = @@ -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 + %s - ~ " matches in %s files"; + note $rak.nr-matches + $rak.nr-changes + ~ " matches in $rak.nr-sources() files"; } else { my str @stats; @@ -1153,24 +1158,27 @@ my sub rak-stats(:$count-only --> Nil) { @stats.unshift: $bar; @stats.push: $bar; } - @stats.push: " Number of files: %s"; + @stats.push: " Number of files: $rak.nr-sources()"; - if %s -> $items { + if $rak.nr-items -> $items { @stats.push: " Number of lines: $items"; } - if %s -> $matches { + if $rak.nr-matches -> $matches { @stats.push: " Number of matches: $matches"; } - if %s -> $passthrus { + if $rak.nr-passthrus -> $passthrus { @stats.push: "Number of passthrus: $passthrus"; } - if %s -> $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."; + } } #------------------------------------------------------------------------------- @@ -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); @@ -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) + !! 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); } @@ -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) { @@ -3041,7 +3073,7 @@ my sub action-modify-files(--> Nil) { %rak := True unless %rak:exists; %rak := %listing:delete // True; - %rak := *.absolute; + %rak := *.absolute; %rak := -> $io, @matches --> Empty { ++$nr-files-seen; @@ -3105,14 +3137,14 @@ 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, ; prepare-needle; %filesystem //= True unless $reading-from-stdin; move-filesystem-options-to-rak; move-result-options-to-rak; - %rak := &handler; + %rak{$producer} := &handler; activate-output-options; run-rak; @@ -3120,12 +3152,19 @@ my sub handle-mbc(str $what, &handler --> Nil) { 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) { @@ -3359,7 +3398,7 @@ my sub action-rename-files(--> Nil) { %rak := True; %rak := True; %rak := True; - %rak := *.absolute; + %rak := *.absolute; %rak := -> $, @files --> Empty { my @existed; my @done; diff --git a/resources/help.txt b/resources/help.txt index 042b221..7225c05 100644 --- a/resources/help.txt +++ b/resources/help.txt @@ -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 @@ -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) @@ -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 diff --git a/resources/help/general.txt b/resources/help/general.txt index 5ebb9af..eac4a6c 100644 --- a/resources/help/general.txt +++ b/resources/help/general.txt @@ -36,8 +36,13 @@ 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 @@ -45,5 +50,4 @@ 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. diff --git a/resources/help/item.txt b/resources/help/item.txt index b3f2375..ed99816 100644 --- a/resources/help/item.txt +++ b/resources/help/item.txt @@ -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 diff --git a/resources/help/result.txt b/resources/help/result.txt index 37de297..8603cf3 100644 --- a/resources/help/result.txt +++ b/resources/help/result.txt @@ -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 @@ -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. diff --git a/xt/01-simple.rakutest b/xt/01-simple.rakutest index c403b08..28077ea 100644 --- a/xt/01-simple.rakutest +++ b/xt/01-simple.rakutest @@ -34,11 +34,12 @@ $paths .= absolute; my sub query-ok( *@query, # the actual parameters - :$ok is copy, # the expected result + :$ok is copy = "", # the expected result :$head = 1, # whether to do the --only-first test with this number :$add-paths = True, # add paths specification :$add-human = True, # add human specification :$add-degree = True, # add degree specification + :$ERR = "", # expected output on STDERR :$add-absolute, # add absolute specification ) is test-assertion { my @args = $*EXECUTABLE.absolute, "-I$dot", $rak, @query.Slip; @@ -53,7 +54,7 @@ my sub query-ok( my $proc := run @args, :out, :err; my $key = "huh?"; - is $proc.err.slurp(:close), "", "is '@query[]' STDERR clean?"; + is $proc.err.slurp(:close), $ERR, "is '@query[]' STDERR correct?"; $add-absolute ?? $proc.out.lines.join("\n") !! $proc.out.lines.map(*.subst($rel, :g)).join("\n") @@ -232,30 +233,30 @@ OK for , <*.words.Slip> { query-ok $_, '--unique', ok => q:to/OK/; -zero -one -two -four -five -SIX -seven eight +five +four nine +one +seven +SIX +two +zero OK } for <*.defined>, <{$_}> { query-ok $_, '--unique', ok => q:to/OK/; -zero -one -two -four -five -SIX -seven eight +five +four nine +one +seven +SIX +two +zero OK } @@ -279,46 +280,51 @@ query-ok '*.comb.Slip', '--frequencies', ok => q:to/OK/; 2:h OK -query-ok 'zero', '--stats-only', :!head, ok => qq:to/OK/; +query-ok 'zero', '--stats-only', :!head, ERR => qq:to/ERR/; ---------------------- Statistics for 'zero': ---------------------- Number of files: 10 Number of lines: 55 Number of matches: 10 -OK +ERR query-ok 'zero', '--count-only', :!head, ok => qq:to/OK/; 10 matches in 10 files OK -query-ok 'eight', <--stats --/highlight>, :!head, ok => qq:to/OK/; +query-ok 'eight', <--stats --/highlight>, :!head, + ok => qq:to/OK/, ERR => qq:to/ERR/; eight 9:eight nine 9:eight +OK ----------------------- Statistics for 'eight': ----------------------- Number of files: 10 Number of lines: 55 Number of matches: 2 -OK +ERR -query-ok 'eight', '--stats', '--highlight', :!head, ok => qq:to/OK/; +my $bon8boff := BON ~ "eight" ~ BOFF; +query-ok 'eight', '--stats', '--highlight', :!head, + ok => qq:to/OK/, ERR => qq:to/ERR/; eight -9:{BON}eight{BOFF} +9:$bon8boff nine -9:{BON}eight{BOFF} +9:$bon8boff +OK ----------------------- Statistics for 'eight': ----------------------- Number of files: 10 Number of lines: 55 Number of matches: 2 -OK +ERR query-ok 'seven', :head(2), ok => qq:to/OK/; seven diff --git a/xt/05-mbc.rakutest b/xt/05-mbc.rakutest index 653c0ec..8407d60 100644 --- a/xt/05-mbc.rakutest +++ b/xt/05-mbc.rakutest @@ -37,12 +37,12 @@ my sub query-ok( } query-ok '--mbc-frames', Q/*.name/, 'mbc', '--unique', ok => qq:to/OK/; + + + eigenstates - - - OK query-ok <--mbc-strings distribution mbc --/highlight>, ok => qq:to/OK/;