Skip to content

Commit

Permalink
0.0.16
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Jul 19, 2022
1 parent 323dcc0 commit bdf76bd
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 15 deletions.
6 changes: 6 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -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<ends-with> 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
Expand Down
6 changes: 3 additions & 3 deletions META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"CLI::Help:ver<0.0.2>:auth<zef:lizmat>",
"CLI::Version:ver<0.0.3>:auth<zef:lizmat>",
"META::constants:ver<0.0.2>:auth<zef:lizmat>",
"highlighter:ver<0.0.11>:auth<zef:lizmat>",
"Files::Containing:ver<0.0.11>:auth<zef:lizmat>",
"highlighter:ver<0.0.12>:auth<zef:lizmat>",
"Files::Containing:ver<0.0.12>:auth<zef:lizmat>",
"as-cli-arguments:ver<0.0.3>:auth<zef:lizmat>",
"Edit::Files:ver<0.0.4>:auth<zef:lizmat>",
"JSON::Fast:ver<0.17>:auth<cpan:TIMOTIMO>"
Expand All @@ -35,5 +35,5 @@
],
"test-depends": [
],
"version": "0.0.15"
"version": "0.0.16"
}
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
-----------------

Expand Down
37 changes: 27 additions & 10 deletions lib/App/Rak.rakumod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The modules that we need here, with their full identities
use highlighter:ver<0.0.11>:auth<zef:lizmat>;
use Files::Containing:ver<0.0.11>:auth<zef:lizmat>;
use highlighter:ver<0.0.12>:auth<zef:lizmat>;
use Files::Containing:ver<0.0.12>:auth<zef:lizmat>;
use as-cli-arguments:ver<0.0.3>:auth<zef:lizmat>;
use Edit::Files:ver<0.0.4>:auth<zef:lizmat>;
use JSON::Fast:ver<0.17>:auth<cpan:TIMOTIMO>;
Expand Down Expand Up @@ -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 "";
Expand Down Expand Up @@ -232,7 +236,9 @@ my sub go-edit-files($editor, $needle, @paths, %_ --> Nil) {

my $files-only := %_<files-with-matches>: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
Expand All @@ -253,7 +259,7 @@ my sub replace-files($needle, @paths, %_ --> Nil) {
my sub count-only($needle, @paths, %_ --> Nil) {
my $files-with-matches := %_<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;
Expand All @@ -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
Expand All @@ -280,7 +286,7 @@ my sub want-lines($needle, @paths, %_ --> Nil) {
my $ignoremark := %_<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 %_<before-context>:delete;
Expand Down Expand Up @@ -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<Raku regular expression|https://docs.raku.org/language/regexes>
(indicated by a string starting and ending with C</>), a
C<Callable> (indicated by a string starting with C<{> and ending with C<}>),
or a a result of L<C<Whatever> 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<all>
the positional arguments are considered to be a path specification.
Expand Down Expand Up @@ -614,6 +623,14 @@ Defaults to C<160> if C<STDOUT> is a TTY (aka, someone is actually watching
the search results), otherwise defaults to C<Inf> 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<words> specified,
will look for pattern as a word in a line, with C<starts-with> will
look for the pattern at the beginning of a line, with C<ends-with>
will look for the pattern at the end of a line, with C<contains> will
look for the pattern at any position in a line.
=head2 --follow-symlinks
Indicate whether symbolic links to directories should be followed. Defaults
Expand Down
62 changes: 61 additions & 1 deletion resources/help.txt
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit bdf76bd

Please sign in to comment.