From 066a3f10065bd9d5910f0799c532c517b162ea8f Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Wed, 31 Aug 2022 12:14:58 +0200 Subject: [PATCH] 0.0.91 --- Changes | 7 ++++ META6.json | 4 +-- README.md | 14 +++++++- doc/App-Rak.rakudoc | 18 +++++++++- lib/App/Rak.rakumod | 69 ++++++++++++++++++++++++------------- resources/help.txt | 1 + resources/help/haystack.txt | 2 +- 7 files changed, 86 insertions(+), 29 deletions(-) diff --git a/Changes b/Changes index 3ff327d..4953337 100644 --- a/Changes +++ b/Changes @@ -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 diff --git a/META6.json b/META6.json index d815c4e..4cdbac9 100644 --- a/META6.json +++ b/META6.json @@ -13,7 +13,7 @@ "has-word:ver<0.0.3>:auth", "highlighter:ver<0.0.14>:auth", "JSON::Fast:ver<0.17>:auth", - "rak:ver<0.0.18>:auth", + "rak:ver<0.0.19>:auth", "String::Utils:ver<0.0.8>:auth", "META::constants:ver<0.0.2>:auth" ], @@ -54,5 +54,5 @@ ], "test-depends": [ ], - "version": "0.0.90" + "version": "0.0.91" } diff --git a/README.md b/README.md index 9f4d267..c065839 100644 --- a/README.md +++ b/README.md @@ -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 ======================= @@ -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 --------------------- @@ -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 ----------------------- diff --git a/doc/App-Rak.rakudoc b/doc/App-Rak.rakudoc index b439148..f7159a8 100644 --- a/doc/App-Rak.rakudoc +++ b/doc/App-Rak.rakudoc @@ -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 @@ -817,6 +821,12 @@ Flag. Indicate whether B 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 @@ -857,6 +867,12 @@ the pattern's C. 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. +=head2 --rak + +Flag. Intended for debugging purposes only. When specified with a trueish +value, will show the named arguments sent to the C subroutine just +before it is being called. + =head2 --recurse-unmatched-dir Flag. Indicate whether directories that didn't match the C<--dir> diff --git a/lib/App/Rak.rakumod b/lib/App/Rak.rakumod index 4f4e149..c44bbfb 100644 --- a/lib/App/Rak.rakumod +++ b/lib/App/Rak.rakumod @@ -4,7 +4,7 @@ use Edit::Files:ver<0.0.4>:auth; use has-word:ver<0.0.3>:auth; use highlighter:ver<0.0.14>:auth; use JSON::Fast:ver<0.17>:auth; -use rak:ver<0.0.18>:auth; +use rak:ver<0.0.19>:auth; use String::Utils:ver<0.0.8>:auth; # Defaults for highlighting on terminals @@ -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:delete -> $files-from { - meh "Specified path&s(@specs) '@specs[]' with --files-from" - if @specs; + meh-with-specs('files-from') if @specs; %rak := $files-from; } # paths from a file elsif %n:delete -> $paths-from { - meh "Specified path&s(@specs) '@specs[]' with --paths-from" - if @specs; + meh-with-specs('paths-from') if @specs; %rak := $paths-from; } - else { + + # paths from command line + elsif %n:delete -> $paths { + meh-with-specs('paths') if @specs; + if $paths eq "-" { + %rak := $paths; + } + else { + %rak := $paths.split(',').List; + } + } + elsif @specs { %rak := @specs.List; } @@ -744,19 +757,30 @@ my sub handle-edit($editor, $pattern, %n, %rak) { my $ignoremark := %n; my $type := %n; - %rak := -> $source, @matches --> Empty { - state @files; - LAST { + if %n:delete { + %rak := True; + %rak = True; + %rak := -> $, @files --> Empty { edit-files @files, :editor(Bool.ACCEPTS($editor) ?? Any !! $editor) } + } + else { + my @files; + %rak := -> $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 + } } } } @@ -1106,20 +1130,21 @@ my multi sub MAIN(*@specs, *%n) { # *%_ causes compilation issues my $group-matches; my $break; + my $has-break; if $show-filename { $group-matches := %n:delete // True; $break = $_ with %n: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:delete; # Debug parameters passed to rak - dd %rak if %n:delete; + if %n:delete { + note .key ~ ': ' ~ .value.raku for %rak.sort(*.key); + } # Do the work, return the result meh-if-unexpected(%n); @@ -1127,10 +1152,6 @@ my multi sub MAIN(*@specs, *%n) { # *%_ causes compilation issues 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: @@ -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 { diff --git a/resources/help.txt b/resources/help.txt index 1186dd6..c4a1087 100644 --- a/resources/help.txt +++ b/resources/help.txt @@ -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 diff --git a/resources/help/haystack.txt b/resources/help/haystack.txt index 9f67a9c..3773196 100644 --- a/resources/help/haystack.txt +++ b/resources/help/haystack.txt @@ -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 @@ -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 -