Skip to content

Commit

Permalink
0.0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Jul 17, 2022
1 parent 1786ce7 commit 1be567c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 31 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.13 2022-07-17T10:17:34+02:00
- Fix issue when there was no config file available
- Remove mentions of now removed option names
- Allow editor to be named with --edit

0.0.12 2022-07-16T22:17:25+02:00
- Process named arg substitutions in the order they are specified
- Remove all aliases for each option: each option can only be accessed
Expand Down
2 changes: 1 addition & 1 deletion META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
],
"test-depends": [
],
"version": "0.0.12"
"version": "0.0.13"
}
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,22 @@ All options are optional. Any unexpected options, will cause an exception to be
--after-context
---------------

Indicate the number of lines that should be shown **after** any line that matches. Defaults to **0**. Will be overridden by a `-C` or `--context` argument.
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
----------------

Indicate the number of lines that should be shown **before** any line that matches. Defaults to **0**. Will be overridden by a `-C` or `--context` argument.
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
---------

Indicate the number of lines that should be shown **around** any line that matches. Defaults to **0**. Overrides any a `-A`, `--after`, `--after-context`, `-B`, `--before` or `--before-context` argument. argument.
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.

--edit
------

Indicate whether the patterns found should be fed into an editor for inspection and/or changes. Defaults to `False`.
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.

--no-filename
-------------
Expand All @@ -84,12 +84,12 @@ Indicate whether the pattern should be highlighted in the line in which it was f
--highlight--after
------------------

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

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

--human
-------
Expand Down
49 changes: 25 additions & 24 deletions lib/App/Rak.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ use CLI::Version:ver<0.0.3>:auth<zef:lizmat> $?DISTRIBUTION, &MAIN;

# Main handler
my multi sub MAIN(*@specs, *%n) { # *%_ causes compilation issues
my %config := from-json($config-file.slurp) if $config-file.e;
my %config := $config-file.e ?? from-json($config-file.slurp) !! { }

# Saving config
if %n<save>:delete -> $option {
Expand All @@ -133,8 +133,8 @@ my multi sub MAIN(*@specs, *%n) { # *%_ causes compilation issues
my @strange;
for original-nameds() -> $option {
my $value := %n{$option};
if Bool.ACCEPTS($value) {
if %config{$option} -> %adding {
if %config{$option} -> %adding {
if Bool.ACCEPTS($value) {
%n{$option}:delete;
if $value {
%n{.key} = .value unless %n{.key}:exists for %adding;
Expand All @@ -143,12 +143,12 @@ my multi sub MAIN(*@specs, *%n) { # *%_ causes compilation issues
%n{.key}:delete for %adding;
}
}
}
else {
@strange.push: "--$option";
else {
@strange.push: "--$option";
}
}
}
meh "These options Must be flags, did you mean: @strange[] ?" if @strange;
meh "These options must be flags, did you mean: @strange[] ?" if @strange;

my $needle = %n<pattern>:delete // @specs.shift;
meh "Must at least specify a pattern" without $needle;
Expand Down Expand Up @@ -182,16 +182,18 @@ my multi sub MAIN(*@specs, *%n) { # *%_ causes compilation issues
!! @specs.&hyperize(1, %n<degree>).map({ paths($_, |%additional).Slip })
).sort(*.fc);

%n<edit>:delete
?? go-edit-files($needle, @paths, %n)
(my $editor := %n<edit>:delete)
?? go-edit-files($editor, $needle, @paths, %n)
!! is-simple-Callable($needle) && (%n<replace-files>:delete)
?? replace-files($needle, @paths, %n)
!! (%n<files-with-matches>:delete)
?? files-only($needle, @paths, %n)
!! want-lines($needle, @paths, %n);
}

my sub go-edit-files($needle, @paths, %_ --> Nil) {
my sub go-edit-files($editor, $needle, @paths, %_ --> Nil) {
CATCH { meh .message }

my $files-only := %_<files-with-matches>:delete;
my %ignore := named-args %_,
:ignorecase<i ignore-case>,
Expand All @@ -201,14 +203,15 @@ my sub go-edit-files($needle, @paths, %_ --> Nil) {

meh-if-unexpected(%_);

edit-files $files-only
edit-files ($files-only
?? files-containing($needle, @paths, :files-only, |%additional)
!! files-containing($needle, @paths, |%additional).map: {
my $path := .key;
.value.map({
$path => .key + 1 => columns(.value, $needle, |%ignore).head
}).Slip
}
}),
:editor(Bool.ACCEPTS($editor) ?? Any !! $editor)
}

my sub replace-files($needle, @paths, %_ --> Nil) {
Expand Down Expand Up @@ -396,26 +399,24 @@ to be thrown with the unexpected options listed.
=head2 --after-context
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<-C> or C<--context>
argument.
matches. Defaults to B<0>. Will be overridden by a C<--context> argument.
=head2 --before-context
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<-C> or C<--context>
argument.
matches. Defaults to B<0>. Will be overridden by a C<--context> argument.
=head2 --context
Indicate the number of lines that should be shown B<around> any line that
matches. Defaults to B<0>. Overrides any a C<-A>, C<--after>,
C<--after-context>, C<-B>, C<--before> or C<--before-context> argument.
argument.
matches. Defaults to B<0>. Overrides any a C<--after-context> or
C<--before-context> arguments.
=head2 --edit
Indicate whether the patterns found should be fed into an editor for
inspection and/or changes. Defaults to C<False>.
inspection and/or changes. Defaults to C<False>. Optionally takes the
name of the editor to be used.
=head2 --no-filename
Expand All @@ -432,15 +433,15 @@ C<True>, else defaults to C<False>.
Indicate the string that should be used at the end of the pattern found in
a line. Only makes sense if C<--highlight> is (implicitely) set to C<True>.
Defaults to the empty string if C<-o> or C<--only-matching> is specified
with a C<True> value, or to the terminal code to end B<bold> otherwise.
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
Indicate the string that should be used at the end of the pattern found in
a line. Only makes sense if C<--highlight> is (implicitely) set to C<True>.
Defaults to a space if C<-o> or C<--only-matching> is specified with a
C<True> value, or to the terminal code to start B<bold> otherwise.
Defaults to a space if C<--only-matching> is specified with a C<True> value,
or to the terminal code to start B<bold> otherwise.
=head2 --human
Expand Down

0 comments on commit 1be567c

Please sign in to comment.