Skip to content

Commit 1dc6e0a

Browse files
committed
0.0.11
1 parent 73a7710 commit 1dc6e0a

File tree

4 files changed

+63
-47
lines changed

4 files changed

+63
-47
lines changed

Changes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ Revision history for App-Rak
22

33
{{$NEXT}}
44

5+
0.0.11 2022-07-16T13:29:57+02:00
6+
- Remove "--with" named argument: you can now use any saved named
7+
argument directly, without having to use --with
8+
- Bump dependency on "highlighter" to get colum fix for regexes
9+
and fix for highlighting on regexes issue
10+
- Bump dependency on "Edit::Files" to not call editor if nothing to edit
11+
512
0.0.10 2022-07-15T23:39:04+02:00
613
- Up dependency on "Edit::Files" in code as well :-(
714

META6.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
],
88
"depends": [
99
"CLI::Version:ver<0.0.3>:auth<zef:lizmat>",
10-
"highlighter:ver<0.0.9>:auth<zef:lizmat>",
10+
"highlighter:ver<0.0.11>: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.3>:auth<zef:lizmat>",
13+
"Edit::Files:ver<0.0.4>: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.10"
34+
"version": "0.0.11"
3535
}

README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,19 @@ This feature can used to both create shortcuts for specific (long) named argumen
148148
$ rak --ignorecase --ignoremark --save=im
149149
Saved configuration for 'im'
150150

151+
# same as --ignorecase --ignoremark
152+
$ rak foo --im
153+
151154
$ rak --follow-symlinks --save=fs
152155
Saved configuration for 'fs'
153156

154157
$ rak --save=foo
155158
Removed configuration for 'foo'
156159
```
157160

158-
See `--with` to add saved named arguments to a query. Please note that no validity checking on the named arguments is being performed at the moment of saving, as validity may depend on other arguments having been specified.
161+
Any saved named arguments can be accessed as if it is a standard named boolean argument. Please note that no validity checking on the named arguments is being performed at the moment of saving, as validity may depend on other arguments having been specified.
159162

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

162165
--sum --summary-if-larger-than
163166
------------------------------
@@ -179,15 +182,18 @@ Indicate whether lines that have the pattern, should have any whitespace at the
179182

180183
If the only argument, shows the name and version of the script, and the system it is running on.
181184

182-
--with
183-
------
185+
CREATING YOUR OWN NAMED ARGUMENTS
186+
=================================
187+
188+
You can use the `--save` named argument to save a set of named arguments and than later access it with the given name:
184189

185190
```bash
186-
# run search with --ignorecase --ignoremark --follow-symlinks
187-
$ rak foo --with=im,fs
188-
```
191+
$ rak --ignorecase --ignoremark --save=im
192+
Saved configuration for 'im'
189193

190-
Add all named arguments previously saved with `--save` with the given tag(s) from the configuration file (`~/.rak-config.json`). Multiple tags can be specified, separated by commas. See `--save` to saved named arguments with a tag.
194+
# same as --ignorecase --ignoremark
195+
$ rak foo --im
196+
```
191197

192198
AUTHOR
193199
======

lib/App/Rak.rakumod

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# The modules that we need here, with their full identities
2-
use highlighter:ver<0.0.9>:auth<zef:lizmat>;
2+
use highlighter:ver<0.0.11>:auth<zef:lizmat>;
33
use Files::Containing:ver<0.0.10>:auth<zef:lizmat>;
44
use as-cli-arguments:ver<0.0.3>:auth<zef:lizmat>;
5-
use Edit::Files:ver<0.0.3>:auth<zef:lizmat>;
5+
use Edit::Files:ver<0.0.4>:auth<zef:lizmat>;
66
use JSON::Fast:ver<0.17>:auth<cpan:TIMOTIMO>;
77

88
# Defaults for highlighting on terminals
@@ -18,11 +18,6 @@ my constant @raku-extensions = <
1818

1919
# Place to keep tagged configurations
2020
my $config-file := $*HOME.add('.rak-config.json');
21-
my %config;
22-
my sub load-config() {
23-
%config := from-json($config-file.slurp) if $config-file.e;
24-
%config
25-
}
2621

2722
# Sane way of quitting
2823
my sub meh($message) { exit note $message }
@@ -97,42 +92,45 @@ use CLI::Version:ver<0.0.3>:auth<zef:lizmat> $?DISTRIBUTION, &MAIN;
9792

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

10197
# Saving config
10298
if %n<save>:delete -> $tag {
103-
load-config;
10499
%n ?? (%config{$tag} := %n) !! (%config{$tag}:delete);
105100
$config-file.spurt: to-json %config, :!pretty, :sorted-keys;
106-
say (%n ?? "Saved" !! "Removed") ~ " configuration for '$tag'";
101+
say (%n ?? "Saved" !! "Removed") ~ " configuration for '--$tag'";
107102
exit;
108103
}
109104

110105
# Show what we have
111106
elsif %n<list-tags>:delete {
112107
meh-if-unexpected(%n);
113108

114-
load-config;
115109
my $format := '%' ~ %config.keys>>.chars.max ~ 's: ';
116110
say sprintf($format,.key) ~ as-cli-arguments(.value)
117111
for %config.sort(*.key.fc);
118112
exit;
119113
}
120114

121-
# Add saved tags if any
122-
if %n<with>:delete -> $with {
123-
my @not-found;
124-
125-
load-config;
126-
for $with.split(',') -> $tag {
115+
# Translate any custom parameters
116+
my @strange;
117+
for %n.sort(*.key.fc) -> (:key($tag), :$value) {
118+
if Bool.ACCEPTS($value) {
127119
if %config{$tag} -> %adding {
128-
%n{.key} = .value unless %n{.key}:exists for %adding;
129-
}
130-
else {
131-
@not-found.push: $tag;
120+
%n{$tag}:delete;
121+
if $value {
122+
%n{.key} = .value unless %n{.key}:exists for %adding;
123+
}
124+
else {
125+
%n{.key}:delete for %adding;
126+
}
132127
}
133128
}
134-
meh "Attempt to add named arguments from unknown tag(s): @not-found[]" if @not-found;
129+
else {
130+
@strange.push: "--$tag";
131+
}
135132
}
133+
meh "Must be flags, did you mean: @strange[] ?" if @strange;
136134

137135
my $needle = %n<pattern>:delete // @specs.shift;
138136
meh "Must at least specify a pattern" without $needle;
@@ -258,12 +256,12 @@ my sub want-lines($needle, @paths, %_ --> Nil) {
258256

259257
&show-line = $trim
260258
?? -> $line {
261-
highlighter $line.trim, $needle, $pre, $post,
259+
highlighter $line.trim, $needle<>, $pre, $post,
262260
:$ignorecase, :$ignoremark, :$only,
263261
:$summary-if-larger-than
264262
}
265263
!! -> $line {
266-
highlighter $line, $needle, $pre, $post,
264+
highlighter $line, $needle<>, $pre, $post,
267265
:$ignorecase, :$ignoremark, :$only,
268266
:$summary-if-larger-than
269267
}
@@ -496,6 +494,9 @@ arguments, or just as a convenient way to combine often used named arguments.
496494
$ rak --ignorecase --ignoremark --save=im
497495
Saved configuration for 'im'
498496
497+
# same as --ignorecase --ignoremark
498+
$ rak foo --im
499+
499500
$ rak --follow-symlinks --save=fs
500501
Saved configuration for 'fs'
501502
@@ -504,12 +505,13 @@ Removed configuration for 'foo'
504505
505506
=end code
506507
507-
See C<--with> to add saved named arguments to a query. Please note that
508-
no validity checking on the named arguments is being performed at the
509-
moment of saving, as validity may depend on other arguments having been
510-
specified.
508+
Any saved named arguments can be accessed as if it is a standard named
509+
boolean argument. Please note that no validity checking on the named
510+
arguments is being performed at the moment of saving, as validity may
511+
depend on other arguments having been specified.
511512
512-
To remove a saved set of named arguments, use C<--save> as the only argument.
513+
To remove a saved set of named arguments, use C<--save> as the only
514+
named argument.
513515
514516
=head2 --sum --summary-if-larger-than
515517
@@ -534,20 +536,21 @@ context for lines was specified, else defaults to C<False>.
534536
If the only argument, shows the name and version of the script, and the
535537
system it is running on.
536538
537-
=head2 --with
539+
=head1 CREATING YOUR OWN NAMED ARGUMENTS
540+
541+
You can use the C<--save> named argument to save a set of named arguments
542+
and than later access it with the given name:
538543
539544
=begin code :lang<bash>
540545
541-
# run search with --ignorecase --ignoremark --follow-symlinks
542-
$ rak foo --with=im,fs
546+
$ rak --ignorecase --ignoremark --save=im
547+
Saved configuration for 'im'
548+
549+
# same as --ignorecase --ignoremark
550+
$ rak foo --im
543551
544552
=end code
545553
546-
Add all named arguments previously saved with C<--save> with the given tag(s)
547-
from the configuration file (C<~/.rak-config.json>). Multiple tags can be
548-
specified, separated by commas. See C<--save> to saved named arguments with
549-
a tag.
550-
551554
=head1 AUTHOR
552555
553556
Elizabeth Mattijsen <liz@raku.rocks>

0 commit comments

Comments
 (0)