diff --git a/Changes b/Changes index 5196257..6d290bd 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,12 @@ Revision history for App-Rak {{$NEXT}} +0.0.16 2022-07-19T17:15:09+02:00 + - Bump dependency on "highlighter" to get ":type support + - Bump dependency on "Files::Containing" to get ":type" support + - Add support for --type functionality + - Initial version of --help documentation + 0.0.15 2022-07-19T12:03:57+02:00 - Add support for -I functionality - Add support for -M functionality diff --git a/META6.json b/META6.json index b46939e..ab16110 100644 --- a/META6.json +++ b/META6.json @@ -9,8 +9,8 @@ "CLI::Help:ver<0.0.2>:auth", "CLI::Version:ver<0.0.3>:auth", "META::constants:ver<0.0.2>:auth", - "highlighter:ver<0.0.11>:auth", - "Files::Containing:ver<0.0.11>:auth", + "highlighter:ver<0.0.12>:auth", + "Files::Containing:ver<0.0.12>:auth", "as-cli-arguments:ver<0.0.3>:auth", "Edit::Files:ver<0.0.4>:auth", "JSON::Fast:ver<0.17>:auth" @@ -35,5 +35,5 @@ ], "test-depends": [ ], - "version": "0.0.15" + "version": "0.0.16" } diff --git a/README.md b/README.md index 7af2330..19ed550 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ POSITIONAL ARGUMENTS pattern ------- -The pattern to search for. This can either be a string, or a regular expression (indicated by a string starting and ending with **/**), or a Callable (indicated by a string starting with **{** and ending with **}**. +The pattern to search for. This can either be a string, or a [Raku regular expression](https://docs.raku.org/language/regexes) (indicated by a string starting and ending with `/`), a `Callable` (indicated by a string starting with `{` and ending with `}`), or a a result of [`Whatever` currying](https://docs.raku.org/type/Whatever) (indicated by a string starting with `*.`). Can also be specified with the `--pattern` option, in which case **all** the positional arguments are considered to be a path specification. @@ -194,6 +194,10 @@ To remove a saved set of named arguments, use `--save` as the only named argumen Indicate the maximum size a line may have before it will be summarized. Defaults to `160` if `STDOUT` is a TTY (aka, someone is actually watching the search results), otherwise defaults to `Inf` effectively (indicating no summarization will ever occur). + * --type[=words|starts-with|ends-with|contains] + +Only makes sense if the pattern is a string. With `words` specified, will look for pattern as a word in a line, with `starts-with` will look for the pattern at the beginning of a line, with `ends-with` will look for the pattern at the end of a line, with `contains` will look for the pattern at any position in a line. + --follow-symlinks ----------------- diff --git a/lib/App/Rak.rakumod b/lib/App/Rak.rakumod index a327e1a..c02b8b0 100644 --- a/lib/App/Rak.rakumod +++ b/lib/App/Rak.rakumod @@ -1,6 +1,6 @@ # The modules that we need here, with their full identities -use highlighter:ver<0.0.11>:auth; -use Files::Containing:ver<0.0.11>:auth; +use highlighter:ver<0.0.12>:auth; +use Files::Containing:ver<0.0.12>:auth; use as-cli-arguments:ver<0.0.3>:auth; use Edit::Files:ver<0.0.4>:auth; use JSON::Fast:ver<0.17>:auth; @@ -110,7 +110,11 @@ my sub HELP($text, @keys, :$verbose) { say "Specific help about '@keys[]':"; say ""; } - say $text; + say $isa-tty + ?? $text.lines.map({ + !.starts-with(" ") && .ends-with(":") ?? BON ~ $_ ~ BOFF !! $_ + }).join("\n") + !! $text; if $verbose { say ""; @@ -232,7 +236,9 @@ my sub go-edit-files($editor, $needle, @paths, %_ --> Nil) { my $files-only := %_:delete; my %ignore := named-args %_, :ignorecase :ignoremark; - my %additional = |(named-args %_, :batch, :degree, :max-count), |%ignore; + my %additional = + |(named-args %_, :max-count, :type, :batch, :degree), + |%ignore; meh-if-unexpected(%_); edit-files ($files-only @@ -253,7 +259,7 @@ my sub replace-files($needle, @paths, %_ --> Nil) { my sub count-only($needle, @paths, %_ --> Nil) { my $files-with-matches := %_:delete; my %additional := named-args %_, - :ignorecase, :ignoremark, :invert-match, :batch, :degree; + :ignorecase, :ignoremark, :invert-match, :type, :batch, :degree; meh-if-unexpected(%_); my int $files; @@ -268,7 +274,7 @@ my sub count-only($needle, @paths, %_ --> Nil) { my sub files-only($needle, @paths, %_ --> Nil) { my %additional := named-args %_, - :ignorecase, :ignoremark, :invert-match, :batch, :degree; + :ignorecase, :ignoremark, :invert-match, :type, :batch, :degree; meh-if-unexpected(%_); say .relative @@ -280,7 +286,7 @@ my sub want-lines($needle, @paths, %_ --> Nil) { my $ignoremark := %_:delete; my $seq := files-containing $needle, @paths, :$ignorecase, :$ignoremark, :offset(1), - |named-args %_, :invert-match, :max-count, :batch, :degree, + |named-args %_, :invert-match, :max-count, :type, :batch, :degree, ; my UInt() $before = $_ with %_:delete; @@ -416,9 +422,12 @@ suggestions are more than welcome! =head2 pattern -The pattern to search for. This can either be a string, or a regular -expression (indicated by a string starting and ending with B), or a -Callable (indicated by a string starting with B<{> and ending with B<}>. +The pattern to search for. This can either be a string, or a +L +(indicated by a string starting and ending with C), a +C (indicated by a string starting with C<{> and ending with C<}>), +or a a result of L currying|https://docs.raku.org/type/Whatever> +(indicated by a string starting with C<*.>). Can also be specified with the C<--pattern> option, in which case B the positional arguments are considered to be a path specification. @@ -614,6 +623,14 @@ Defaults to C<160> if C is a TTY (aka, someone is actually watching the search results), otherwise defaults to C effectively (indicating no summarization will ever occur). +=item --type[=words|starts-with|ends-with|contains] + +Only makes sense if the pattern is a string. With C specified, +will look for pattern as a word in a line, with C will +look for the pattern at the beginning of a line, with C +will look for the pattern at the end of a line, with C will +look for the pattern at any position in a line. + =head2 --follow-symlinks Indicate whether symbolic links to directories should be followed. Defaults diff --git a/resources/help.txt b/resources/help.txt index 1065073..59d7510 100644 --- a/resources/help.txt +++ b/resources/help.txt @@ -1 +1,61 @@ -See https://raku.land/zef:lizmat/App::Rak for now. +Pattern specification: + foo string + '/ << bar >> /' Raku regex indicated by being bounded by / / + '{ .ends-with("bar") }' Raku code indicated by being bounded by { } + '*.starts--with("foo")' Raku WhateverCode starting with *. +either as first argument, or as --pattern=foo option + +String search pattern modifiers: + --ignorecase Ignore distinction between upper, lower and title case letters + --ignoremark Only compare base characters, ignore additional marks + --type=words Look for string as a word + --type=starts-with Look for string at start of a line + --type=ends-with Look for string at end of a line + --type=contains Look for string anywhere (default) + +Code pattern helpers: + --I=lib First look for any modules to load in the "lib" directory + --M=foo Load module "foo" before compiling Raku code pattern + +Haystack specification: + all other arguments (default: current directory) + --follow-symlinks Whether to follow symlinked directories (default: don't) + +Result modifiers: + --only-matching Only produce the actual matches + --summary-if-larger-than=N Summarize matching line if longer than N chars + --trim Remove whitespace, true if no context + --highlight Highlight matches if possible + --highlight-before=xxx String to put before match + --highlight-after=yyy String to put after match + --count-only Only return count of matches + --files-with-matches Only return filenames with matches + +Listing modifiers: + --before-context=N List N lines before any line with a match + --after-context=N List N lines after any line with a match + --context=N List N lines around any line with a match + +Resource usage: + --batch=N max number of files to process in a thread (default: 64) + --degree=N max number of threads to use for processing (default: cores - 1) + +Edit options: + --edit[=editor] Go edit the result in an editor, (default EDITOR or vim) + +Option management: + --save=name Translate --name to all other options specified, + remove if --save was the only option specified + --list-additional-options List all previously saved options + +General options: + --help Show this + --help foo Show additional help about: pattern | string | code | haystack | + result | listing | resource | edit | option | general + --version Show version information + --verbose Be more verbose, if applicable + +Option format: + --foo Option "foo" is True + --/foo Option "foo" is False + --foo=bar Option "foo" is "bar"