Skip to content

Commit df9c906

Browse files
committed
0.2
1 parent e9ae633 commit df9c906

File tree

8 files changed

+105
-44
lines changed

8 files changed

+105
-44
lines changed

Changes

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
Revision history for App-Rak
22

33
{{$NEXT}}
4+
5+
0.2 2022-10-28T13:38:31+02:00
6+
- Add support for --patterns-from
7+
- Add support for --type=auto|regex|code, make --type leading
48
- Fixed a (implicit) --smartcase blocking use of --unicode
59
- Bumped dependency on highlighter to get multiple needle support
610
- Fix issue with handling unknown extension groups, Mustafa Aydın++
7-
- Add support for --patterns-from
8-
- Add support for --type=auto|regex|code
911

1012
0.1.12 2022-10-22T13:04:37+02:00
1113
- Add dependency on IO::Path::AutoDecompress to make --auto-decompress

META6.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"as-cli-arguments:ver<0.0.7>:auth<zef:lizmat>",
1010
"CLI::Version:ver<0.0.8>:auth<zef:lizmat>",
1111
"has-word:ver<0.0.3>:auth<zef:lizmat>",
12-
"highlighter:ver<0.0.16>:auth<zef:lizmat>",
12+
"highlighter:ver<0.0.17>:auth<zef:lizmat>",
1313
"IO::Path::AutoDecompress:ver<0.0.2>:auth<zef:lizmat>",
1414
"JSON::Fast::Hyper:ver<0.0.3>:auth<zef:lizmat>",
1515
"META::constants:ver<0.0.3>:auth<zef:lizmat>",
@@ -58,5 +58,5 @@
5858
],
5959
"test-depends": [
6060
],
61-
"version": "0.1.12"
61+
"version": "0.2"
6262
}

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ Flag. If specified with a True value, will accept compressed files with the `.gz
305305

306306
Only applicable if `--csv-per-line` has been specified. Flag. If (implicitly) specified, will show diagnostic information about problems that occurred during parsing of the CSV file. The default is `True`.
307307

308-
backtrace
309-
---------
308+
--backtrace
309+
-----------
310310

311311
Flag. When specified with a True value, will interpret either standard input, or a single file, as a Raku backtrace. And produce a result containing the lines of source code from that backtrace. Can be used together with `--context`, `--before-context`, `--after-context`, `--edit` and `--vimgrep`. Any pattern specification will only be used for highlighting. If **not** used in combination with `--edit` or `--vimgrep`, will assume a context of 2 lines.
312312

@@ -1113,6 +1113,11 @@ Indicate the path of the file to read path specifications from instead of from a
11131113

11141114
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 saved with `--save`, and thus freeze a specific pattern as part of a custom option.
11151115

1116+
--patterns-from=file
1117+
--------------------
1118+
1119+
Alternative way to specify one or more patterns to search for. Reads the indicated file and interprets each line as a pattern according to the rules (implicitly) set with the `--type` argument.
1120+
11161121
--per-file[=code]
11171122
-----------------
11181123

doc/App-Rak.rakudoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,12 @@ actually a path specification, rather than a pattern. This allows
13821382
the pattern to be saved with C<--save>, and thus freeze a specific
13831383
pattern as part of a custom option.
13841384

1385+
=head2 --patterns-from=file
1386+
1387+
Alternative way to specify one or more patterns to search for. Reads the
1388+
indicated file and interprets each line as a pattern according to the rules
1389+
(implicitly) set with the C<--type> argument.
1390+
13851391
=head2 --per-file[=code]
13861392

13871393
Indicate whether matching should be done per file, rather than per line.

lib/App/Rak.rakumod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# The modules that we need here, with their full identities
22
use as-cli-arguments:ver<0.0.7>:auth<zef:lizmat>; # as-cli-arguments
33
use has-word:ver<0.0.3>:auth<zef:lizmat>; # has-word
4-
use highlighter:ver<0.0.16>:auth<zef:lizmat>; # columns highlighter matches
4+
use highlighter:ver<0.0.17>:auth<zef:lizmat>; # columns highlighter matches
55
use IO::Path::AutoDecompress:ver<0.0.2>:auth<zef:lizmat>; # IOAD
66
use JSON::Fast::Hyper:ver<0.0.3>:auth<zef:lizmat>; # from-json to-json
77
use META::constants:ver<0.0.3>:auth<zef:lizmat> $?DISTRIBUTION;
@@ -19,7 +19,7 @@ my constant BON = "\e[1m"; # BOLD ON
1919
my constant BOFF = "\e[22m"; # BOLD OFF
2020

2121
#- start of available options --------------------------------------------------
22-
#- Generated on 2022-10-22T22:32:01+02:00 by tools/makeOPTIONS.raku
22+
#- Generated on 2022-10-28T13:23:53+02:00 by tools/makeOPTIONS.raku
2323
#- PLEASE DON'T CHANGE ANYTHING BELOW THIS LINE
2424
my str @options = <absolute accept accessed after-context allow-loose-escapes allow-loose-quotes allow-whitespace auto-decompress auto-diag backtrace backup batch before-context blame-per-file blame-per-line blocks break checkout classify categorize context count-only created csv-per-line degree deny description device-number dir dont-catch dryrun ecosystem edit encoding eol escape exec extensions file file-separator-null files-from files-with-matches files-without-matches filesize find find-all formula frequencies gid group group-matches hard-links has-setgid has-setuid help highlight highlight-after highlight-before human ignorecase ignoremark inode invert-match is-empty is-executable is-group-executable is-group-readable is-group-writable is-owned-by-group is-owned-by-user is-owner-executable is-owner-readable is-owner-writable is-readable is-sticky is-symbolic-link is-world-executable is-world-readable is-world-writable is-writable json-per-elem json-per-file json-per-line keep-meta known-extensions list-custom-options list-expanded-options list-known-extensions matches-only max-matches-per-file meta-modified mode modified modify-files module only-first output-dir output-file pager paragraph-context passthru passthru-context paths paths-from pattern patterns-from per-file per-line proximate rename-files quietly quote rak recurse-symlinked-dir recurse-unmatched-dir repository save sayer sep shell show-blame show-filename show-item-number silently smartcase sourcery stats stats-only strict summary-if-larger-than trim type uid under-version-control unicode unique user verbose version vimgrep with-line-endings>;
2525
#- PLEASE DON'T CHANGE ANYTHING ABOVE THIS LINE

resources/help.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@ Arguments overview:
22
‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒
33

44
Pattern specification:
5+
Either as first argument, or as --pattern=foo option, or as pattern(s)
6+
in --patterns-from=file option.
57
foo literal string
68
'/ << bar >> /' Raku regex indicated by being bounded by / /
79
'{ .ends-with("bar") }' Raku code indicated by being bounded by { }
810
'*.starts-with("foo")' Raku WhateverCode starting with *
9-
either as first argument, or as --pattern=foo option
11+
--type=auto Interpret special markers in pattern as above (default)
12+
--type=regex Interpret pattern as a regex (without special markers)
13+
--type=code Interpret pattern as code (without special markers)
14+
--type=words Look for pattern as a word
15+
--type=starts-with Look for pattern at start of a line
16+
--type=ends-with Look for pattern at end of a line
17+
--type=contains Look for pattern anywhere (default if no special markers)
1018

1119
String search pattern modifiers:
1220
--ignorecase Ignore distinction between upper, lower and title case letters
1321
--ignoremark Only compare base characters, ignore additional marks
1422
--smartcase As --ignorecase if pattern does *NOT* contain any uppercase
15-
--type=words Look for string as a word
16-
--type=starts-with Look for string at start of a line
17-
--type=ends-with Look for string at end of a line
18-
--type=contains Look for string anywhere (default)
1923

2024
Item producers:
2125
--per-line[=producer] Produce lines for pattern matching

resources/help/pattern.txt

Lines changed: 66 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,43 @@
11
Pattern specification:
22
‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒‒
33

4-
There are 2 ways in which a pattern can be specified:
4+
There are 3 ways in which pattern(s) can be specified:
55

66
1. As the first positional argument
7-
2. With the --pattern argument
7+
2. Or with the --pattern=foo argument
8+
3. Or using the --patterns-from=file argument
89

9-
The latter can be handy if you want to create a short-cut to searching
10-
for a particular string with --save.
10+
The first is easiest for a quick ad-hoc search. The second can be handy
11+
if you want to create a short-cut to searching for a particular string with
12+
--save. The last one allows you set up a set of patterns to be searched
13+
for simultaneously.
1114

12-
Patterns come in 3 flavours:
13-
14-
1. as a literal string
15-
2. as a regex (the Raku name for "regular expression")
16-
3. as a piece of code (a Callable in Raku)
15+
If the --patterns-from=file argument is specified, it will read the content
16+
of the given file and process each line as a pattern specification, as
17+
described below. When searching, each pattern is tried on an item, and
18+
accepted as soon as a pattern matched. Any highlighting will occur on
19+
*that* match only.
1720

18-
If a literal string is specified as a pattern, then by default
19-
any item of which the stringification contains that string, will
20-
be accepted.
21+
If a literal string is specified as a pattern, then by default any item of
22+
which the stringification contains that string, will be accepted.
2123

2224
Example:
2325
# produce any lines that have "foo" in them
2426
$ rak foo
2527

26-
Literal strings matching can be further specialize with the --type
27-
argument, which can have 4 possible values
28+
Patterns come in 3 flavours:
2829

29-
1. contains string must occur anywhere in item
30-
2. words string must be surrounded by (virtual) whitespace in item
31-
3. starts-with item must *start* with string
32-
4. ends-with item must *end* with string
30+
1. as a literal string
31+
2. as a regex (the Raku name for "regular expression")
32+
3. as a piece of code (a Callable in Raku)
3333

34-
Example:
35-
# produce any lines that have the word "bar" in them
36-
$ rak bar --type=words
34+
Whether something you specified is interpreted as a regex or as code, or
35+
just as a string, is determined by the --type argument. By default, the
36+
--type arguments assumes "auto". When this is (implicitly) specified,
37+
then the string will be checked for special markers to deduce the intended
38+
type of pattern.
39+
40+
Regex:
3741

3842
If a string that starts and ends with '/' is specified as a pattern,
3943
it is considered to be a regex and will be compiled as such. Any
@@ -45,11 +49,17 @@ Example:
4549
# produce any lines that have the word "bar" in them
4650
$ rak '/ << bar >> /'
4751

48-
Both literal string matching, as well as matching with a regex, are
49-
sensitive to the --ignorecase and --ignoremark arguments.
52+
If --type=regex has been specified, you should omit the '/' at either end of
53+
the string:
54+
55+
Example:
56+
# produce any lines that have the word "bar" in them
57+
$ rak '<< bar >>' --type=regex
58+
59+
Code:
5060

5161
If a string that starts with '{' and ends with '}' is specified, or
52-
a string that starts with '*.', they will be considered to be Raku
62+
a string that starts with '*', they will be considered to be Raku
5363
executable code and compiled as such. Each item will be passed as
5464
a positional argument to the compiled code, and the code is expected
5565
to return a value that is either:
@@ -61,7 +71,7 @@ to return a value that is either:
6171
5. Slip produce all items in the Slip, always
6272
6. product produce that, always
6373

64-
True and False are returned for any condition.
74+
True or False are returned for any condition.
6575

6676
Empty is returned for any failed conditional construct, such as "if",
6777
"unless", "with" or "without".
@@ -85,8 +95,38 @@ $ rak '*.uc'
8595
# produce only lines uppercased that have "foo" in them
8696
$ rak '{ .uc if .contains("foo") }'
8797

88-
# produce all lines, only uppercase the ones that have "foo" in them
98+
# produce all lines, only uppercase the ones that have "rakudoc" in them
8999
$ rak '{.contains("rakudoc") ?? .uc !! $_}'
90100

91101
# produce all unique words
92102
$ rak '*.words.Slip'
103+
104+
If --type=code has been specified, you should omit the '{' and '}', or
105+
omit the initial '*':
106+
107+
Examples:
108+
# produce uppercased lines
109+
$ rak '.uc' --type=code
110+
111+
# produce all lines, only uppercase the ones that have "rakudoc" in them
112+
$ rak '.contains("rakudoc") ?? .uc !! $_' --type=code
113+
114+
Other types:
115+
116+
Literal strings matching can be further specialized with other values of the
117+
--type argument:
118+
119+
- contains string must occur anywhere in item
120+
- words string must be surrounded by (virtual) whitespace in item
121+
- starts-with item must *start* with string
122+
- ends-with item must *end* with string
123+
124+
Examples:
125+
# produce any lines that have the word "bar" in them
126+
$ rak bar --type=words
127+
128+
# produce any lines that start with "Example"
129+
$ rak Example --type=starts-with
130+
131+
Both literal string matching, as well as matching with a regex, are
132+
sensitive to the --smartcase, --ignorecase and --ignoremark arguments.

xt/02-simple.rakutest

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ my sub query-ok(
8080
# Checks for "ine"
8181
my @ine = (
8282
<ine>,
83+
<ine --type=auto>,
84+
<ine --type=regex>,
8385
<ine --type=ends-with>,
8486
<INE --type=ends-with --ignorecase>,
8587
<ïñę --type=ends-with --ignoremark>,
@@ -124,14 +126,16 @@ for (
124126
query-ok .Slip, '--highlight', :ok("\n");
125127
}
126128

127-
query-ok "six",
128-
<--smartcase --/group-matches --/show-item-number --/highlight --/break>,
129-
ok => q:to/OK/;
129+
for "six", ('.lc eq "six"', '--type=code') {
130+
query-ok .Slip,
131+
<--smartcase --/group-matches --/show-item-number --/highlight --/break>,
132+
ok => q:to/OK/;
130133
six:SIX
131134
seven:SIX
132135
eight:SIX
133136
nine:SIX
134137
OK
138+
}
135139

136140
query-ok <seven --type=words>, :head(2), ok => qq:to/OK/;
137141
seven
@@ -211,7 +215,7 @@ for </\w+/>, <*.words.Slip> {
211215
OK
212216
}
213217

214-
for <*.&defined>, <{$_}> {
218+
for <*.defined>, <{$_}> {
215219
query-ok $_, '--frequencies', ok => q:to/OK/;
216220
10:zero
217221
9:one
@@ -240,7 +244,7 @@ nine
240244
OK
241245
}
242246

243-
for <*.&defined>, <{$_}> {
247+
for <*.defined>, <{$_}> {
244248
query-ok $_, '--unique', ok => q:to/OK/;
245249
zero
246250
one

0 commit comments

Comments
 (0)