Skip to content

Commit

Permalink
0.0.91
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Aug 31, 2022
1 parent 70acdaf commit 066a3f1
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 29 deletions.
7 changes: 7 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ Revision history for App-Rak

{{$NEXT}}

0.0.91 2022-08-31T12:14:16+02:00
- Make --find / --edit combination work
- Document / Refine the --rak debugging option
- Add --paths option, for specifying paths as named argument
- Bump dependency on "rak" to get uvc fix
- Hopefully workaround spesh issue causing execution errors

0.0.90 2022-08-30T23:53:04+02:00
- A complete rework of the internals. Instead of having its own
internal engine, now depends on the new "rak" module for the
Expand Down
4 changes: 2 additions & 2 deletions META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"has-word:ver<0.0.3>:auth<zef:lizmat>",
"highlighter:ver<0.0.14>:auth<zef:lizmat>",
"JSON::Fast:ver<0.17>:auth<cpan:TIMOTIMO>",
"rak:ver<0.0.18>:auth<zef:lizmat>",
"rak:ver<0.0.19>:auth<zef:lizmat>",
"String::Utils:ver<0.0.8>:auth<zef:lizmat>",
"META::constants:ver<0.0.2>:auth<zef:lizmat>"
],
Expand Down Expand Up @@ -54,5 +54,5 @@
],
"test-depends": [
],
"version": "0.0.90"
"version": "0.0.91"
}
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ path(s)

Optional. Either indicates the path of the directory (and its sub-directories), or the file that will be searched. By default, all directories that do not start with a period, will be recursed into (but this can be changed with the `--dir` option).

By default, all files will be searched in the directories. This can be changed with the `--file` option
By default, all files will be searched in the directories. This can be changed with the `--file` option.

Paths can also be specified with the `--paths` option, in which case there should only be a positional argument for the pattern, or none if `--pattern` option was used for the pattern specification.

ON CALLABLES AS PATTERN
=======================
Expand Down Expand Up @@ -674,6 +676,11 @@ $ tail -f ~/access.log | rak --passthru 123.45.67.89

Flag. Indicate whether **all** lines from source should be shown if at least one line matches. Highlighting will still be performed, if so (implicitely) specified.

--paths=path1,path2
-------------------

Indicates the path specification to be used instead of from any positional arguments. "-" can be specified to read path specifications from STDIN. Multiple path specifications should be separated by comma's.

--paths-from=filename
---------------------

Expand Down Expand Up @@ -704,6 +711,11 @@ Flag. Only makes sense if the pattern is a `Callable`. If specified with a true

Only applicable if `--csv-per-line` has been specified. Indicates the character that should be used for quoting fields. Defaults to **double quote**.

--rak
-----

Flag. Intended for debugging purposes only. When specified with a trueish value, will show the named arguments sent to the `rak` subroutine just before it is being called.

--recurse-unmatched-dir
-----------------------

Expand Down
18 changes: 17 additions & 1 deletion doc/App-Rak.rakudoc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ directories that do not start with a period, will be recursed into (but
this can be changed with the C<--dir> option).

By default, all files will be searched in the directories. This can be
changed with the C<--file> option
changed with the C<--file> option.

Paths can also be specified with the C<--paths> option, in which case there
should only be a positional argument for the pattern, or none if C<--pattern>
option was used for the pattern specification.

=head1 ON CALLABLES AS PATTERN

Expand Down Expand Up @@ -817,6 +821,12 @@ Flag. Indicate whether B<all> lines from source should be shown if at
least one line matches. Highlighting will still be performed, if so
(implicitely) specified.

=head2 --paths=path1,path2

Indicates the path specification to be used instead of from any positional
arguments. "-" can be specified to read path specifications from STDIN.
Multiple path specifications should be separated by comma's.

=head2 --paths-from=filename

Indicate the path of the file to read path specifications from instead of
Expand Down Expand Up @@ -857,6 +867,12 @@ the pattern's C<Callable>. Defaults to False.
Only applicable if C<--csv-per-line> has been specified. Indicates the
character that should be used for quoting fields. Defaults to B<double quote>.

=head2 --rak

Flag. Intended for debugging purposes only. When specified with a trueish
value, will show the named arguments sent to the C<rak> subroutine just
before it is being called.

=head2 --recurse-unmatched-dir

Flag. Indicate whether directories that didn't match the C<--dir>
Expand Down
69 changes: 45 additions & 24 deletions lib/App/Rak.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use Edit::Files:ver<0.0.4>:auth<zef:lizmat>;
use has-word:ver<0.0.3>:auth<zef:lizmat>;
use highlighter:ver<0.0.14>:auth<zef:lizmat>;
use JSON::Fast:ver<0.17>:auth<cpan:TIMOTIMO>;
use rak:ver<0.0.18>:auth<zef:lizmat>;
use rak:ver<0.0.19>:auth<zef:lizmat>;
use String::Utils:ver<0.0.8>:auth<zef:lizmat>;

# Defaults for highlighting on terminals
Expand Down Expand Up @@ -385,20 +385,33 @@ my sub handle-general-options(%n) { # *%_ causes compilation issues
# Set up paths to search
my sub setup-sources-selection(@specs, %n, %rak) {

my sub meh-with-specs($name) {
meh "Specified path&s(@specs) '@specs[]' with --$name"
}

# files from a file
if %n<files-from>:delete -> $files-from {
meh "Specified path&s(@specs) '@specs[]' with --files-from"
if @specs;
meh-with-specs('files-from') if @specs;
%rak<files-from> := $files-from;
}

# paths from a file
elsif %n<paths-from>:delete -> $paths-from {
meh "Specified path&s(@specs) '@specs[]' with --paths-from"
if @specs;
meh-with-specs('paths-from') if @specs;
%rak<paths-from> := $paths-from;
}
else {

# paths from command line
elsif %n<paths>:delete -> $paths {
meh-with-specs('paths') if @specs;
if $paths eq "-" {
%rak<paths-from> := $paths;
}
else {
%rak<paths> := $paths.split(',').List;
}
}
elsif @specs {
%rak<paths> := @specs.List;
}

Expand Down Expand Up @@ -744,19 +757,30 @@ my sub handle-edit($editor, $pattern, %n, %rak) {
my $ignoremark := %n<ignoremark>;
my $type := %n<type>;

%rak<mapper> := -> $source, @matches --> Empty {
state @files;
LAST {
if %n<find>:delete {
%rak<find> := True;
%rak<omit-item-number> = True;
%rak<mapper> := -> $, @files --> Empty {
edit-files
@files,
:editor(Bool.ACCEPTS($editor) ?? Any !! $editor)
}
}
else {
my @files;
%rak<mapper> := -> $source, @matches --> Empty {
LAST {
edit-files
@files,
:editor(Bool.ACCEPTS($editor) ?? Any !! $editor)
}

my $path := $source.relative;
@files.append: @matches.map: {
$path => .key => columns(
.value, $pattern, :$ignorecase, :$ignoremark, :$type
).head
my $path := $source.relative;
@files.append: @matches.map: {
$path => .key => columns(
.value, $pattern, :$ignorecase, :$ignoremark, :$type
).head
}
}
}
}
Expand Down Expand Up @@ -1106,31 +1130,28 @@ my multi sub MAIN(*@specs, *%n) { # *%_ causes compilation issues

my $group-matches;
my $break;
my $has-break;
if $show-filename {
$group-matches := %n<group-matches>:delete // True;
$break = $_ with %n<break>:delete // $group-matches;
unless $break<> =:= False {
$break = "" but True
if Bool.ACCEPTS($break) || ($break.defined && !$break);
}
$break = "" if $break<> =:= True;
$has-break = !($break.defined && $break<> =:= False);
}

# Remove arguments that have been handled now
%n<ignorecase ignoremark type>:delete;

# Debug parameters passed to rak
dd %rak if %n<rak>:delete;
if %n<rak>:delete {
note .key ~ ': ' ~ .value.raku for %rak.sort(*.key);
}

# Do the work, return the result
meh-if-unexpected(%n);
my $rak := rak $needle, %rak;
meh .message with $rak.exception;
note "Unexpected leftovers: %rak.raku()" if %rak;

my &source-post-proc = {
IO::Path.ACCEPTS($_) ?? .relative !! $_
}

# show the results!
my int $seen;
RESULT:
Expand All @@ -1153,7 +1174,7 @@ my multi sub MAIN(*@specs, *%n) { # *%_ causes compilation issues
elsif Iterable.ACCEPTS($value) {
if $value -> @matches {
my $source := $key.relative;
sayer $break if $break && $seen;
sayer $break if $has-break && $seen;

if PairContext.ACCEPTS(@matches.head) {
if $group-matches {
Expand Down
1 change: 1 addition & 0 deletions resources/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Code pattern helpers:

Haystack specification:
path1 path2 ... All other arguments are paths (default: current dir)
--paths Comma separated list of paths instead of ^^
--extensions By group (e.g. #raku) and/or comma separated
--files-from=file Read files to inspect from given file
--known-extensions Only search files with known extensions
Expand Down
2 changes: 1 addition & 1 deletion resources/help/haystack.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Haystack specification:
path1 path2 ... All other arguments are paths (default: current dir)
--paths Comma separated list of paths instead of ^^
--extensions By group (e.g. #raku) and/or comma separated
--files-from=file Read files to inspect from given file
--known-extensions Only search files with known extensions
Expand All @@ -10,4 +11,3 @@ Haystack specification:
--dir=expression Directory basename filter, default: not ^.
--file=expression File basename filter, default: all
--find-all Override --dir / --file defaults

0 comments on commit 066a3f1

Please sign in to comment.