Skip to content

Commit d44ed5e

Browse files
committed
0.0.9
1 parent ba67812 commit d44ed5e

File tree

4 files changed

+41
-19
lines changed

4 files changed

+41
-19
lines changed

Changes

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ Revision history for App-Rak
22

33
{{$NEXT}}
44

5+
0.0.9 2022-07-15T23:29:55+02:00
6+
- Up dependency on "Edit::Files" to get nvim support
7+
- Add support for --pattern, allowing pattern to be saved with --save
8+
59
0.0.8 2022-07-15T15:59:26+02:00
610
- Add dependency on "JSON::Fast"
711
- Add support for --save=tag functionality
@@ -24,7 +28,7 @@ Revision history for App-Rak
2428

2529
0.0.5 2022-07-10T15:26:55+02:00
2630
- No longer follow symlinked directories by default
27-
- Bump dependency on Files::Containing to get :follow-symlinks capablity
31+
- Bump dependency on Files::Containing to get :follow-symlinks capability
2832
- Add -S / --follow-symlinks arguments to follow symlinked directories
2933

3034
0.0.4 2022-07-09T14:22:33+02:00

META6.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"highlighter:ver<0.0.9>:auth<zef:lizmat>",
1111
"Files::Containing:ver<0.0.10>:auth<zef:lizmat>",
1212
"as-cli-arguments:ver<0.0.3>:auth<zef:lizmat>",
13-
"Edit::Files:ver<0.0.2>:auth<zef:lizmat>",
13+
"Edit::Files:ver<0.0.3>:auth<zef:lizmat>",
1414
"JSON::Fast:ver<0.17>:auth<cpan:TIMOTIMO>"
1515
],
1616
"description": "a CLI for searching strings in files",
@@ -31,5 +31,5 @@
3131
],
3232
"test-depends": [
3333
],
34-
"version": "0.0.8"
34+
"version": "0.0.9"
3535
}

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ POSITIONAL ARGUMENTS
3535
pattern
3636
-------
3737

38-
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 **}**.
38+
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 **}**.
39+
40+
Can also be specified with the `--pattern` named argument, in which case all the positional arguments are considered to be a path specification.
3941

4042
path(s)
4143
-------
@@ -125,6 +127,11 @@ Indicate whether only the matched pattern should be produced, rather than the li
125127

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

130+
--pattern
131+
---------
132+
133+
Alternative way to specify the pattern to search for. If (implicitely) 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`.
134+
128135
--replace-files
129136
---------------
130137

lib/App/Rak.rakumod

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,15 @@ my sub add-before-after($io, @initially-selected, int $before, int $after) {
8989
@selected
9090
}
9191

92+
# Entry point for CLI processing
93+
my proto sub MAIN(|) is export {*}
94+
9295
# Make sure we can do -V --version
93-
use CLI::Version:ver<0.0.3>:auth<zef:lizmat>
94-
$?DISTRIBUTION,
95-
my proto sub MAIN(|) is export {*}
96+
use CLI::Version:ver<0.0.3>:auth<zef:lizmat> $?DISTRIBUTION, &MAIN;
97+
98+
# Main handler
99+
my multi sub MAIN(*@specs, *%n) { # *%_ causes compilation issues
96100

97-
# Processing "save" and "list-tags" requests
98-
my multi sub MAIN(*%n) { # *%_ causes compilation issues
99101
# Saving config
100102
if %n<save>:delete -> $tag {
101103
load-config;
@@ -104,6 +106,7 @@ my multi sub MAIN(*%n) { # *%_ causes compilation issues
104106
say (%n ?? "Saved" !! "Removed") ~ " configuration for '$tag'";
105107
exit;
106108
}
109+
107110
# Show what we have
108111
elsif %n<list-tags>:delete {
109112
meh-if-unexpected(%n);
@@ -114,20 +117,15 @@ my multi sub MAIN(*%n) { # *%_ causes compilation issues
114117
for %config.sort(*.key.fc);
115118
exit;
116119
}
117-
meh "Must at least specify a pattern";
118-
}
119-
120-
# The main processor
121-
my multi sub MAIN($needle, *@specs, *%n) { # *%_ causes compilation issues
122-
meh "Saving pattern and/or paths not supported" if %n<save>:delete;
123120

124-
# Running one or more configs
121+
# Add saved tags if any
125122
if %n<with>:delete -> $with {
126123
my @not-found;
124+
127125
load-config;
128126
for $with.split(',') -> $tag {
129127
if %config{$tag} -> %adding {
130-
%n{.key} = .value for %adding;
128+
%n{.key} = .value unless %n{.key}:exists for %adding;
131129
}
132130
else {
133131
@not-found.push: $tag;
@@ -136,6 +134,9 @@ my multi sub MAIN($needle, *@specs, *%n) { # *%_ causes compilation issues
136134
meh "Attempt to add named arguments from unknown tag(s): @not-found[]" if @not-found;
137135
}
138136

137+
my $needle = %n<pattern>:delete // @specs.shift;
138+
meh "Must at least specify a pattern" without $needle;
139+
139140
if $needle.starts-with('/') && $needle.ends-with('/') {
140141
$needle .= EVAL;
141142
}
@@ -147,7 +148,7 @@ my multi sub MAIN($needle, *@specs, *%n) { # *%_ causes compilation issues
147148
}
148149

149150
temp $*OUT;
150-
with named-arg %n, <output-file> -> $path {
151+
with %n<output-file>:delete -> $path {
151152
$*OUT = open($path, :w) if $path ne "-";
152153
}
153154

@@ -357,7 +358,10 @@ suggestions are more than welcome!
357358
358359
The pattern to search for. This can either be a string, or a regular
359360
expression (indicated by a string starting and ending with B</>), or a
360-
Callable (indicated by a string starting with B<{> and ending with B<}>.
361+
Callable (indicated by a string starting with B<{> and ending with B<}>.
362+
363+
Can also be specified with the C<--pattern> named argument, in which
364+
case all the positional arguments are considered to be a path specification.
361365
362366
=head2 path(s)
363367
@@ -465,6 +469,13 @@ the line in which the pattern was found. Defaults to C<False>.
465469
Indicate the path of the file in which the result of the search should
466470
be placed. Defaults to C<STDOUT>.
467471
472+
=head2 --pattern
473+
474+
Alternative way to specify the pattern to search for. If (implicitely)
475+
specified, will assume the first positional parameter specified is
476+
actually a path specification, rather than a pattern. This allows
477+
the pattern to be searched for to be saved with C<--save>.
478+
468479
=head2 --replace-files
469480
470481
Only makes sense if the specified pattern is a C<Callable>. Indicates

0 commit comments

Comments
 (0)