Skip to content

Commit

Permalink
0.0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Jul 19, 2022
1 parent 016dad5 commit 323dcc0
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 34 deletions.
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ Revision history for App-Rak

{{$NEXT}}

0.0.15 2022-07-19T12:03:57+02:00
- Add support for -I functionality
- Add support for -M functionality
- Worked a bit on the pod

0.0.14 2022-07-18T20:47:50+02:00
- Add dependency on META::constants
- Add dependency on CLI::Help to get --help support
Expand Down
2 changes: 1 addition & 1 deletion META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
],
"test-depends": [
],
"version": "0.0.14"
"version": "0.0.15"
}
62 changes: 42 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ SUPPORTED OPTIONS

All options are optional. Any unexpected options, will cause an exception to be thrown with the unexpected options listed.

--after-context
---------------
--after-context=N
-----------------

Indicate the number of lines that should be shown **after** any line that matches. Defaults to **0**. Will be overridden by a `--context` argument.

--before-context
----------------
--before-context=N
------------------

Indicate the number of lines that should be shown **before** any line that matches. Defaults to **0**. Will be overridden by a `--context` argument.

--context
---------
--context=N
-----------

Indicate the number of lines that should be shown **around** any line that matches. Defaults to **0**. Overrides any a `--after-context` or `--before-context` arguments.

Expand All @@ -71,11 +71,26 @@ Indicate the number of lines that should be shown **around** any line that match

Indicate whether just the number of lines with matches should be calculated. When specified with a `True` value, will show a "N matches in M files" by default, and if the `:files-with-matches` option is also specified with a `True` value, will also list the file names with their respective counts.

--edit
------
--edit[=editor]
---------------

Indicate whether the patterns found should be fed into an editor for inspection and/or changes. Defaults to `False`. Optionally takes the name of the editor to be used.

-I=dir
------

Indicate the directory that should be searched for Raku module loading. Only makes sense if the pattern is executable code.

Please note that contrary to normal use in Raku, the `=` **must** be specified. Also note that you can create a shortcut for most often used arguments of the `-I` option:

```bash
$ rak --I=. --save=I.
Saved option '--I.' as: --I='.'

$ rak --I=lib --save=Ilib
Saved option '--Ilib' as: --I=lib
```

--no-filename
-------------

Expand All @@ -86,13 +101,13 @@ Indicate whether filenames should **not** be shown. Defaults to `False` if `--hu

Indicate whether the pattern should be highlighted in the line in which it was found. Defaults to `True` if `--human` is (implicitly) set to `True`, else defaults to `False`.

--highlight--after
------------------
--highlight--after[=string]
---------------------------

Indicate the string that should be used at the end of the pattern found in a line. Only makes sense if `--highlight` is (implicitly) set to `True`. Defaults to the empty string if `--only-matching` is specified with a `True` value, or to the terminal code to end **bold** otherwise.

--highlight--before
-------------------
--highlight--before[=string]
----------------------------

Indicate the string that should be used at the end of the pattern found in a line. Only makes sense if `--highlight` is (implicitly) set to `True`. Defaults to a space if `--only-matching` is specified with a `True` value, or to the terminal code to start **bold** otherwise.

Expand Down Expand Up @@ -122,18 +137,25 @@ If specified with a true value and as the only option, will list all additional

Indicate whether line numbers should be shown. Defaults to `True` if `--human` is (implicitly) set to `True` and <-h> is **not** set to `True`, else defaults to `False`.

-M=module
---------

Indicate the Raku module that should be loaded. Only makes sense if the pattern is executable code.

Please note that contrary to normal use in Raku, the `=` **must** be specified.

--only-matching
---------------

Indicate whether only the matched pattern should be produced, rather than the line in which the pattern was found. Defaults to `False`.

--output-file
-------------
--output-file=filename
----------------------

Indicate the path of the file in which the result of the search should be placed. Defaults to `STDOUT`.

--pattern
---------
--pattern=foo
-------------

Alternative way to specify the pattern to search for. If (implicitly) specified, will assume the first positional parameter specified is actually a path specification, rather than a pattern. This allows the pattern to be searched for to be saved with `--save`.

Expand All @@ -142,8 +164,8 @@ Alternative way to specify the pattern to search for. If (implicitly) specified,

Only makes sense if the specified pattern is a `Callable`. Indicates whether the output of the pattern should be applied to the file in which it was found. Defaults to `False`.

--save
------
--save=name
-----------

Save all named arguments with the given name in the configuration file (`~/.rak-config.json`), and exit with a message that these options have been saved with the given name.

Expand All @@ -167,8 +189,8 @@ Any saved named arguments can be accessed as if it is a standard named boolean a

To remove a saved set of named arguments, use `--save` as the only named argument.

--summary-if-larger-than
------------------------
--summary-if-larger-than=N
--------------------------

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).

Expand Down
64 changes: 51 additions & 13 deletions lib/App/Rak.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,26 @@ my multi sub MAIN(*@specs, *%n) { # *%_ causes compilation issues
my $needle = %n<pattern>:delete // @specs.shift;
meh "Must at least specify a pattern" without $needle;

# Return prelude from -I and -M parameters
my sub prelude() {
my $prelude = "";
if %n<I>:delete -> \libs {
$prelude = libs.map({"use lib '$_'; "}).join;
}
if %n<M>:delete -> \modules {
$prelude ~= modules.map({"use $_; "}).join;
}
$prelude
}

if $needle.starts-with('/') && $needle.ends-with('/') {
$needle .= EVAL;
}
elsif $needle.starts-with('{') && $needle.ends-with('}') {
$needle = ('-> $_ ' ~ $needle).EVAL;
$needle = (prelude() ~ '-> $_ ' ~ $needle).EVAL;
}
elsif $needle.starts-with('*.') {
$needle = $needle.EVAL;
$needle = (prelude() ~ $needle).EVAL;
}

temp $*OUT;
Expand Down Expand Up @@ -334,7 +346,6 @@ my sub want-lines($needle, @paths, %_ --> Nil) {
without $line-number {
$line-number = !$no-filename if $human;
}

meh-if-unexpected(%_);

my int $nr-files;
Expand Down Expand Up @@ -427,17 +438,17 @@ changed with the C<--file> option
All options are optional. Any unexpected options, will cause an exception
to be thrown with the unexpected options listed.
=head2 --after-context
=head2 --after-context=N
Indicate the number of lines that should be shown B<after> any line that
matches. Defaults to B<0>. Will be overridden by a C<--context> argument.
=head2 --before-context
=head2 --before-context=N
Indicate the number of lines that should be shown B<before> any line that
matches. Defaults to B<0>. Will be overridden by a C<--context> argument.
=head2 --context
=head2 --context=N
Indicate the number of lines that should be shown B<around> any line that
matches. Defaults to B<0>. Overrides any a C<--after-context> or
Expand All @@ -450,12 +461,31 @@ When specified with a C<True> value, will show a "N matches in M files"
by default, and if the C<:files-with-matches> option is also specified with
a C<True> value, will also list the file names with their respective counts.
=head2 --edit
=head2 --edit[=editor]
Indicate whether the patterns found should be fed into an editor for
inspection and/or changes. Defaults to C<False>. Optionally takes the
name of the editor to be used.
=head2 -I=dir
Indicate the directory that should be searched for Raku module loading.
Only makes sense if the pattern is executable code.
Please note that contrary to normal use in Raku, the C<=> B<must> be
specified. Also note that you can create a shortcut for most often used
arguments of the C<-I> option:
=begin code :lang<bash>
$ rak --I=. --save=I.
Saved option '--I.' as: --I='.'
$ rak --I=lib --save=Ilib
Saved option '--Ilib' as: --I=lib
=end code
=head2 --no-filename
Indicate whether filenames should B<not> be shown. Defaults to C<False> if
Expand All @@ -467,14 +497,14 @@ Indicate whether the pattern should be highlighted in the line in which
it was found. Defaults to C<True> if C<--human> is (implicitly) set to
C<True>, else defaults to C<False>.
=head2 --highlight--after
=head2 --highlight--after[=string]
Indicate the string that should be used at the end of the pattern found in
a line. Only makes sense if C<--highlight> is (implicitly) set to C<True>.
Defaults to the empty string if C<--only-matching> is specified with a
C<True> value, or to the terminal code to end B<bold> otherwise.
=head2 --highlight--before
=head2 --highlight--before[=string]
Indicate the string that should be used at the end of the pattern found in
a line. Only makes sense if C<--highlight> is (implicitly) set to C<True>.
Expand Down Expand Up @@ -513,17 +543,25 @@ Indicate whether line numbers should be shown. Defaults to C<True> if
C<--human> is (implicitly) set to C<True> and <-h> is B<not> set to C<True>,
else defaults to C<False>.
=head2 -M=module
Indicate the Raku module that should be loaded. Only makes sense if the
pattern is executable code.
Please note that contrary to normal use in Raku, the C<=> B<must> be
specified.
=head2 --only-matching
Indicate whether only the matched pattern should be produced, rather than
the line in which the pattern was found. Defaults to C<False>.
=head2 --output-file
=head2 --output-file=filename
Indicate the path of the file in which the result of the search should
be placed. Defaults to C<STDOUT>.
=head2 --pattern
=head2 --pattern=foo
Alternative way to specify the pattern to search for. If (implicitly)
specified, will assume the first positional parameter specified is
Expand All @@ -536,7 +574,7 @@ Only makes sense if the specified pattern is a C<Callable>. Indicates
whether the output of the pattern should be applied to the file in which
it was found. Defaults to C<False>.
=head2 --save
=head2 --save=name
Save all named arguments with the given name in the configuration file
(C<~/.rak-config.json>), and exit with a message that these options have
Expand Down Expand Up @@ -569,7 +607,7 @@ depend on other arguments having been specified.
To remove a saved set of named arguments, use C<--save> as the only
named argument.
=head2 --summary-if-larger-than
=head2 --summary-if-larger-than=N
Indicate the maximum size a line may have before it will be summarized.
Defaults to C<160> if C<STDOUT> is a TTY (aka, someone is actually watching
Expand Down

0 comments on commit 323dcc0

Please sign in to comment.