/
App-Rak.rakudoc
2122 lines (1419 loc) · 69.5 KB
/
App-Rak.rakudoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
=begin pod
=head1 NAME
App::Rak - 21st century grep / find / ack / ag / rg on steroids
=head1 SYNOPSIS
=begin code :lang<bash>
# look for "foo" in current directory recursively
$ rak foo
# look for "foo" in directory "bar" recursively
$ rak foo bar
# look for "foo" as word in current directory
$ rak '/ << foo >> /'
# look for "foo", only produce filenames
$ rak foo --files-with-matches
# also produce 2 lines before and after
$ rak foo --before=2 --after=2
# lines with foo AND bar
$ rak '{.contains("foo") && .contains("bar")}'
=end code
=head1 DESCRIPTION
App::Rak provides a CLI called C<rak> that allows you to look for a pattern
in (a selection of files) from one or more directories recursively. It has
been modelled after utilities such as C<grep>, C<ack>, C<ag> and C<rg>, with
a little bit of C<find> mixed in, and C<-n> and C<-p> parameters of many
programming languages.
Note: this project is now in beta-development phase. Comments, suggestions
and bug reports continue to be more than welcome!
=head1 POSITIONAL ARGUMENTS
=head2 pattern
The pattern to search for.
Can also be specified with the C<--pattern> option, in which case B<all>
the positional arguments are considered to be a path specification.
Patterns will be interpreted in the following ways if B<no> C<--type>
has been specified, or C<--type=auto> has been specified.
Multiple patterns, stored in a file or read from STDIN, can also be specified
with the <C--patterns-from> argument.
=head3 / regex /
If the pattern starts and ends with C</>, then it indicates a Raku
L<regex|https://docs.raku.org/language/regexes>. B<No> special processing
of the given string between slashes will be done: the given pattern will be
parsed as a regex verbatim. During the search process, each item will be
matched against this regex. Any C<--ignorecase> or C<--ignoremark> arguments
will be honoured.
=head3 { code }
If the pattern starts with C<{> and ends with C<}>, then it indicates
Raku code to be executed. B<No> special processing of the given string
between the curly braces will be done: the given code will be compiled as
Raku code. During the search process, this code will be run for each item,
available in C<$_>. To facilitate the use of libraries that wish to access
that topic, it is also available as the C<$*_> dynamic variable.
The dynamic variable C<$*SOURCE> will contain the C<IO::Path> object of the
file being processed. Note that the Raku code will be called in a thread
B<unsafe> manner.
The dynamic variable C<$*_> will contain the topic with which the code was
called. This to allow custom libraries to easily obtain the topic without
the user needing to specify that again.
=head3 *code
If the pattern starts with C<*>, then this is a short way of specifying Raku
code as a pattern, using
L<Whatever-currying|https://docs.raku.org/type/Whatever#index-entry-Whatever-currying>. Otherwise the same as C<{ code }>.
=head3 jp:path
If the pattern start with 'jp:', then interpret the rest of the pattern as
a C<JSON path>. Only makes sense when used together with C<--json-per-file>,
C<--json-per-line> or C<--json-per-elem>. Requires that the
L<C<JSON::Path>|https://raku.land/cpan:JNTHN/JSON::Path> module is installed.
Basically a shortcut to specifying C<path --type=json-path>.
=head4 Supported JSON path syntax
$ root node
.key index hash key
['key'] index hash key
[2] index array element
[0,1] index array slice
[4:5] index array range
[:5] index from the beginning
[-3:] index to the end
.* index all elements
[*] index all elements
[?(expr)] filter on Raku expression
..key search all descendants for hash key
A query that is not rooted from $ or specified using .. will be evaluated
from the document root (that is, same as an explicit $ at the start).
=head4 Full Raku support
The C<jp:path> and C<--type=json-path> syntax are actually syntactic sugar
for calling a dedicated C<jp> subroutine that takes a JSON path as its
argument, and returns an instantiated C<JP> object.
This means that:
=begin code :lang<bash>
$ rak --json-per-file jp:foo
$ rak --json-per-file --type=json-path foo
=end code
are a different way of saying:
=begin code :lang<bash>
$ rak --json-per-file '{ jp("path").Slip }'
=end code
using the "pattern is Raku code" syntax.
The following methods can be called on the C<JP> object:
.value The first selected value.
.values All selected values as a Seq.
.paths The paths of all selected values as a Seq.
.paths-and-values Interleaved selected paths and values.
Without listing all of the methods that can be called on the C<JP> object,
one should note that all efforts have been made to make the C<JP> object
act like a C<Seq>.
=head3 ^string
If the pattern starts with C<^>, then it indicates the string should be at
the B<start> of each item. Basically a shortcut to specifying
C<string --type=starts-with>. Any C<--smartcase>, C<--smartmark>,
C<--ignorecase> or C<--ignoremark> arguments will be honoured.
=head3 string$
If the pattern ends with C<$>, then it indicates the string should be at
the B<end> of each item. Basically a shortcut to specifying
C<string --type=ends-with>. Any C<--smartcase>, C<--smartmark>,
C<--ignorecase> or C<--ignoremark> arguments will be honoured.
=head3 ^string$
If the pattern starts with C<^> and ends with C<$>, then it indicates that
the string should be equal to the item. Basically a shortcut to specifying
C<string --type=equal>. Any C<--smartcase>, C<--ignorecase> or C<--ignoremark>
arguments will be honoured.
=head3 §string
If the pattern starts with C<§>, then it indicates that the string should
occur as a word (with word-boundaris on both ends) in the item. Basically a
shortcut to specifying C<string --type=words>. Any C<--smartcase>,
C<--smartmark>, C<--ignorecase> or C<--ignoremark> arguments will be honoured.
=head3 string
If there are no special start or end markers, then it indicates that the
string should occur somewhere in the item. Basically a shortcut to
specifying C<string --type=contains>. Any C<--smartcase>, C<--smartmark>,
C<--ignorecase> or C<--ignoremark> arguments will be honoured.
=head2 path(s)
Optional. Either indicates the path of the directory (and its
sub-directories), or the file that will be searched, or a URL that will
produce a file to be searched. By default, all directories that do not
start with a period, and which are not symbolic links, will be recursed
into (but this can be changed with the C<--dir> option).
By default, all files with known extensions will be searched in the
directories. This can be changed with the C<--file> option, or specialized
version of that like C<--extensions>.
Paths can also be specified with the C<--paths> option, in which case there
should only be a positional argument for the pattern, or none if C<--pattern>
option was used for the pattern specification.
=head1 ON CALLABLES AS PATTERN
C<Callables> can be specified by a string starting with C<*.> (so-called
L<Whatever currying|https://docs.raku.org/type/Whatever>, or as a string
starting with C<{> and ending with C<}>.
Note that if a C<Callable> is specified as a pattern, then no highlighting
can be performed as it cannot signal why or where a match occurred.
The return value of the pattern C<Callable> match is interpreted in the
following way:
=head2 True
If the C<Bool>ean True value is returned, assume the pattern is found.
Produce the item unless C<--invert-match> was specified.
=head2 False
If the C<Bool>ean False value is returned, assume the pattern is B<not>
found. Do B<not> produce the item unless C<--invert-match> was specified.
=head2 Nil
If C<Nil> is returned, assume the pattern is B<not> found.
This typically happens when a C<try> is used in a pattern, and an execution
error occurred. Do B<not> produce the item unless C<--invert-match> was
specified.
=head2 Empty
If the empty C<Slip> is returned, assume the pattern is B<not> found.
Do B<not> produce the item unless C<--invert-match> was specified. Shown
in stats as a C<passthru>.
=head2 any other Slip
If a non-empty C<Slip> is returned, produce the values of the C<Slip>
separately for the given item (each with the same item number).
=head3 any other value
Produce that value.
=head1 PHASERS IN CALLABLE PATTERNS
The Raku Programming Language has a number of unique features that can
be used with patterns that are executable code. One of them is the use
of so-called L<phasers|https://docs.raku.org/language/phasers> (pieces
of code that will be executed automatically when a certain condition has
been met.
C<App::Rak> currently supports all of Raku's
L<loop phasers|https://docs.raku.org/language/phasers#FIRST>:
=item FIRST - code to run when searching starts
=item NEXT - code to run when searching a file is done
=item LAST - code to run when searching is done
These phasers will be called in a B<thread-safe> manner.
=begin code :lang<bash>
# show number of files inspected before the search result
$ rak '{ state $s = 0; NEXT $s++; LAST say "$s files"; .contains("foo")}'
# show number of files inspected after of the search result
$ rak '{ state $s = 0; NEXT $s++; END say "$s files"; .contains("foo")}'
=end code
Note that the use of the C<LAST> phaser will make the search run eagerly,
meaning that no results will be shown until the search has been completed.
Any other phasers that do not require special attention by C<App::Rak>
are also supported in any code specified (such as C<BEGIN> and C<END>).
=head1 ON THE INTERPRETATION OF OPTIONS
All options when using App::Rak, start with either one dash C<-> or two
dashes C<-->.
If an option starts with two dashes, it is a so-called "long option".
Any characters after the dashes are considered to be the single name of
the option.
If an option starts with a single dash, then it is considered to be a
collection of "short options", each of 1 letter. If the number of short
options is 1, then it can be followed by a numerical value (without equal
sign).
If the specification of the option does B<not> contain an equal sign C<=>,
then the option is interpreted as a boolean option. By default, such a flag
is considered to represent C<True>. The value can be negated in two ways:
=item a slash before the name
=item the string "no-" before the name
Some examples:
=item -i
Option "i" is True.
=item -j5
Option "j" has the value 5.
=item -im
Options "i" and "m" are True.
=item -/i
Option "i" is False.
=item -/im
Options "i" and "m" are False.
=item -no-i
Option "i" is False.
=item --foo
Option "foo" is True.
=item --/foo
Option "foo" is False.
=item --no-foo
Option "foo" is False.
If the specification of an option contains an equal sign after the name,
then whatever follows that, is considered the value of that option. Whether
or not that value needs to be quoted, and how they are to be quoted, really
depends on the shell that you use to access `rak`. Generally, if the value
consists of alphanumeric characters only, no quoting is necessary. Otherwise
it's better to quote your values.
Some examples:
=item -s=foo
Option "s" has the value "foo".
=item -t='foo bar'
Option "t" has the value "foo bar".
=item --frobnicate=yes
Option "frobnicate" has the value "yes".
=head1 CREATING YOUR OWN OPTIONS
App::Rak provides B<many> options. If you are happy with a set of options
for a certain workflow, You can use the C<--save> option to save that set
of options and than later access them with the given name:
=begin code :lang<bash>
# create -i shortcut for ignoring case
$ rak --ignorecase --save=i
Saved option '-i' as: --ignorecase
# create -m shortcut for ignoring accents
$ rak --ignoremark --save=m
Saved option '-m' as: --ignoremark
# same as --ignorecase --ignoremark
$ rak foo -im
=end code
Generally speaking, the most used boolean options can be saved as single
letter options: this allows multiple options to be specified in a single,
short manner (as shown above).
To better document / remember what a particular custom option is meant to
do, you can add a description with the C<--description> option.
=begin code :lang<bash>
# add a description to the -i custom option
$ rak --description='Search without caring for uppercase' --save=i
Saved '--description='Search without caring for uppercase'' as: -i
# add an option -g for searching only git files
$ rak --description='Committed files only' --under-version-control --save=g
Saved '--description='Committed files only' --under-version-control' as: -g
=end code
There is also a special named option that indicates the options that will
be automatically activated on any invocation: C<(default)>.
=begin code :lang<bash>
# enable --smartcase by default on every run
$ rak --smartcase --save='(default)'
Saved '--smartcase' as: (default)
=end code
You can use the C<--list-custom-options> to see what options you have saved
before.
Custom options are saved in C<~/.rak-config.json>. You can override this
by specifying the C<RAK_CONFIG> environment variable.
=begin code :lang<bash>
# read custom options from ".custom.json" (in the current directory)
$ RAK_CONFIG=.custom.json rak foo
=end code
You can also use the C<RAK_CONFIG> variable to disable loading any
configuration by not specifying a value:
=begin code :lang<bash>
# start rak without any custom configuration
$ RAK_CONFIG= rak foo
=end code
=head1 SUPPORTED OPTIONS
All options are optional. Any unexpected options, will cause an exception
to be thrown with the unexpected options listed and possible alternatives
mentioned. Unless specifically indicated otherwise, using the negation of
a flag has the same effect as B<not> specifying it.
=head2 --absolute
Flag. If specified indicates that whenever paths are shown, they will be
shown as absolute paths. Defaults to C<False>, which will cause paths to
be produced as paths relative to the current directory.
=head2 --accept=code
Specifies the code that should be executed that should return C<True> if
the path is acceptable, given an C<IO::Path> object of the path. See also
C<--deny>.
=begin code :lang<bash>
# Include files that have "use Test" in them
$ rak --accept='*.slurp.contains("use Test")'
=end code
=head2 --accessed=condition
If specified, indicates the C<Callable> that should return True to include a
file in the selection of files to be checked. The access time of the file
(number of seconds since epoch, as a C<Num> value) will be passed as the
only argument. Note that many file systems do not actually support this
reliably.
See "CHECKING TIMES ON FILES" for more information about features that
can be used inside the C<Callable>.
=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 --allow-loose-escapes
Only applicable if C<--csv-per-line> has been specified. Flag. If specified,
indicates that B<any> character may be escaped.
=head2 --allow-loose-quotes
Only applicable if C<--csv-per-line> has been specified. Flag. If specified,
indicates that fields do not need to be quoted to be acceptable.
=head2 --allow-whitespace
Only applicable if C<--csv-per-line> has been specified. Flag. If specified,
indicates that whitespace is allowed around separators.
=head2 --auto-decompress
Flag. If specified with a True value, will accept compressed files
with the C<.gz> (gzip) or C<.bz2> (bzip2) extension, if the extension was
otherwise acceptable. Will automatically decompress files for inspection.
=head2 --auto-diag
Only applicable if C<--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 C<True>.
=head2 --backtrace
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 C<--context>, C<--before-context>, C<--after-context>,
C<--edit> and C<--vimgrep>. Any pattern specification will only be used
for highlighting. If B<not> used in combination with C<--edit> or
C<--vimgrep>, will assume a context of 2 lines.
=begin code :lang<bash>
# look at source of a stacktrace
$ raku script 2>&1 | rak --backtrace
# inspect the source of a stacktrace in an editor
$ raku script 2>&1 | rak --backtrace --edit
# inspect a backtrace stored in a file
$ rak --backtrace filename
=end code
=head2 --backup[=extension]
Indicate whether backups should be made of files that are being modified.
If specified without extension, the extension C<.bak> will be used.
=head2 --batch[=N]
Indicate the number of files that should be checked per thread. If specified
as a flag, will assue C<1>. Defaults to C<64> if not specified. See also
<--degree>.
=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 --blame-per-file
Flag. Only makes sense if the pattern is a C<Callable>. If specified,
indicates that each of the selected files will be provided as
L<C<Git::Blame::File>|https://raku.land/zef:lizmat/Git::Blame::File#methods-on-gitblamefile>
objects if C<git blame> can be performed on the a selected file. If that
is not possible, then the selected file will be ignored.
If <git blame> information can be obtained, then the associated
C<Git::Blame::File> object will be presented to the pattern C<Callable>.
If the Callable returns C<True>, then the filename will be produced. If
anything else is returned, then the stringification of that object will be
produced.
=begin code :lang<bash>
# show files with more than 10 commits
$ rak '*.commits > 10' --blame-per-file --files-with-matches
=end code
Requires that the L<C<Git::Blame::File>|https://raku.land/zef:lizmat/Git::Blame::File> module is installed.
=head2 --blame-per-line
Flag. Only makes sense if the pattern is a C<Callable>. If specified,
indicates that each line from the selected files will be provided as
L<C<Git::Blame::Line>|https://raku.land/zef:lizmat/Git::Blame::File#accessors-on-gitblameline>
objects if C<git blame> can be performed on the a selected file. If that
is not possible, then the selected file will be ignored.
If <git blame> information can be obtained, then the associated
C<Git::Blame::Line> object will be presented to the pattern C<Callable>.
If the Callable returns C<True>, then the short representation of the
C<git blame> information will be produced. If the returned value is anything
else, then the stringification of that object will be produced.
=begin code :lang<bash>
# show git blame on lines of which the author is "Scooby Doo"
$ rak '{ .author eq "Scooby Doo" }' --blame-per-line
=end code
Requires that the L<C<Git::Blame::File>|https://raku.land/zef:lizmat/Git::Blame::File> module is installed.
=head2 --blocks=condition
If specified, indicates the C<Callable> that should return True to include a
file in the selection of files to be checked. The number of logical blocks
that a file takes up in the filesystem, will be passed as the only argument.
=begin code :lang<bash>
# show files that consist of at least 3 blocks
$ rak --find --blocks='* >= 3'
=end code
=head2 --break[=string]
Indicate whether there should be a visible division between matches of
different files. Can also be specified as a string to be used as the
divider. Defaults to C<True> (using an empty line as a divider) if
C<--group-matches> is (implicitly) set to C<True>, else defaults to C<False>.
=head2 --checkout=branch
Only valid if the current directory is under git version control. Indicate
the branch to checkout by the general matching logic of App::Rak. Will
produce listing of matching branches if more than one, or say that there
is no match. Branches need not have been checked out locally yet.
=head2 --categorize=categorizer
If specified, indicates the C<Callable> that should return zero or more
keys for a given line to have it categorized. This effectively replaces
the filename if a line by its key in the result. See also C<--classify>.
=begin code :lang<bash>
# categorize by the first two letters of a line
$ rak --categorize='*.substr(0,2).comb'
=end code
=head2 --classify=classifier
If specified, indicates the C<Callable> that should return a key for a
given line to have it classified. This effectively replaces the filename
if a line by its key in the result. See also C<--categorize>.
=begin code :lang<bash>
# classify by the last letter of a line
$ rak --classify='*.substr(*-1)'
=end code
=head2 --context=N
Indicate the number of lines that should be produced B<around> any line that
matches. Defaults to B<0>.
=head2 --count-only
Flag. Indicate whether just the number of lines with matches should be
calculated. When specified with a C<True> value, will show a "N matches
in M files" by default, and if the C<:files-with-matches> (or
C<files-without matches>) option is also specified with a C<True> value,
will just show total counts. See also C<--stats-only>.
=head2 --created=condition
If specified, indicates the C<Callable> that should return True to include a
file in the selection of files to be checked. The creation time of the file
(number of seconds since epoch, as a C<Num> value) will be passed as the
only argument.
See "CHECKING TIMES ON FILES" for more information about features that
can be used inside the C<Callable>.
=head2 --csv-per-line
Flag. Only makes sense if the pattern is a C<Callable>. If specified with a
C<True> value, indicates that selected files should be interpreted as
comma separated values (CSV). Each row from the selected files will be
provided as a list of strings (or as C<CSV::Field> objects if C<--keep-meta>
was specified).
Attempt to interpret file as a CSV file, and pass each row as a List to
to the pattern Callable. Only files with extensions from the C<#csv> group
will be tried, unless overridden by any explicit extension specification.
More documentation can be found with the
L<Text::CSV|https://raku.land/github:Tux/Text::CSV> module itself.
=begin code :lang<bash>
# Show the values of the column named "foo" of the rows in the "info.csv"
# file if the column named "bar" is equal to "foo"
$ rak --csv-per-line '{.<foo> if .<bar> eq "foo"}' info.csv
# Show the values of the first column of the rows in the "info.csv" file
# if the second column is equal to "foo"
$ rak --csv-per-line --/headers '{.[0] if .[1] eq "foo"}' info.csv
=end code
=head2 --degree[=N | code]
Indicate the number of worker threads that should be maximally. Defaults
to the number of cores minus 1 if not specified. Assumes C<1> if specified
as a flag. Can also take a C<Callable> specification, in which case the
number of CPU cores will be presented to that Callable as the only argument.
See also <--batch>.
=head2 --deny=code
Specifies the code that should be executed that should return C<True> if
the path is B<NOT> acceptable, given an C<IO::Path> object of the path.
See also C<--accept>.
=begin code :lang<bash>
# Include files that **NOT** have "use Test" in them
$ rak --deny='*.slurp.contains("use Test")'
=end code
=head2 --description=text
Specify a description to be saved with the custom option. This will be
shown prominently with --list-custom-options. If it is the only argument
apart from --save, then the discription will be added (if there was no
description yet) or replace the current description of the option.
=head2 --device-number=condition
If specified, indicates the C<Callable> that should return True to include a
file in the selection of files to be checked. The device number of the
filesystem on which the file is located, will be passed as the only argument.
=head2 --dir=condition
If specified, indicates the C<Callable> that should return True to have a
directory be included for further recursions in file selection. The basename
of the directory will be passed as the only argument. Defaults to all
directories that do not start with a period. Can specify as a flag to
include B<all> directories for recursion.
=head2 --dont-catch
Flag. If specified as a flag, will B<not> catch any error during processing,
but will throw any error again. Defaults to C<False>, making sure that
errors B<will> be caught. Mainly intended for debugging and error reporting.
=head2 --dryrun
Flag. Indicate to B<not> actually make any changes to any content
modification if specified with a C<True> value. Only makes sense together
with the C<--modify-files> and the C<--rename-files> option.
=head2 --ecosystem[=name1,name2]
Intended to be used by Raku ecosystem maintainers. Indicates the name of
zero or more Raku ecosystems of which to inspect the C<META6.json>
information of all its modules. Currently supported names are:
=item p6c - the original git ecosystem (deprecated)
=item cpan - the ecosystem piggybacking on PAUSE / CPAN (deprecated)
=item fez - the currently recommended ecosystem for new modules / updates
=item rea - the Raku Ecosystem Archive
Defaults to C<rea> if specified as a flag. Implies C<--json-per-elem>.
=begin code :lang<bash>
# show all unique module names by an author from the REA
$ rak '{ .author eq "Scooby Doo" }' --ecosystem
# same, but now from the p6c and cpan ecosystems
$ rak '{ .author eq "Scooby Doo" }' --ecosystem=p6c,cpan
=end code
Assumes C<zef> is installed and its meta information is available.
=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. If no editor is specified, will use what
is in the C<EDITOR> environment variable. If that is not specified either,
will call "vim".
=head2 --eol=lf|cr|crlf
Only applicable if C<--csv-per-line> has been specified. Indicate a
line ending different from the standard line ending assumed by the system.
Can be specified as C<lf> for a single LineFeed character, C<cr> for a
single CarriageReturn character, or C<crlf> for a combination of a
CarriageReturn and a LineFeed character.
=head2 --escape=char
Only applicable if C<--csv-per-line> has been specified. Indicates the
escape character to be used to escape characters in a field. Defaults to
B<double quote>.
=head2 --exec=invocation
If specified, indicates the name of a program and its arguments to be
executed. Any C<$_> in the invocation string will be replaced by the file
being checked. The file will be included if the program runs to a successful
conclusion.
=head2 --execute-raku[=code]
Flag or code specification. When specified with a True value, will
use the pattern as the name of a script to execute. If code is specified
will execute that code. If the code consists of "-", then will read code
from STDIN to execute. Any execution error's backtrace will be used
to produce a result with the lines of source code of that backtrace.
Can be used together with C<--context>, C<--before-context>,
C<--after-context>, C<--edit> and C<--vimgrep>. Will assume a context of
2 lines if B<not> used in combination with C<--edit> or C<--vimgrep>,
If C<--verbose> is specified, will try to create an extended (--ll-exception)
backtrace.
=begin code :lang<bash>
# look at source of a stacktrace after running script
$ rak --execute-raku script
# inspect the source of a stacktrace in an editor
$ rak --execute-raku script --edit
# inspect a backtrace from execution of code read from STDIN
$ cat script | rak --execute-raku=-
=end code
=head2 --extensions=spec
Indicate the extensions of the filenames that should be inspected.
By default, only files with known extensions, will be searched.
Extensions can be specified as a comma-separated list of either a
a predefined group of extensions (indicated by C<#name>), a single
extension, or C<*> to indicate all known extensions.
=begin code :lang<bash>
# inspect files with extensions used by Raku and Perl
$ rak foo --extensions=#raku,#perl
# inspect files with presumable Markdown content
$ rak foo --extensions=md,markdown
# inspect files without extension
$ rak foo --extensions=
# inspect files without extension or with the extension "foo"
$ rak foo --extensions=,foo
=end code
Predefined groups are C<#raku>, C<#perl>, C<#cro>, C<#text>, C<#c>, C<#c++>,
C<#yaml>, C<#ruby>, C<#python>, C<#html>, C<#markdown>, C<#js>, C<#json>,
C<#jsonl>, C<#csv>, C<#config> and C<#text>.
The C<--list-known-extensions> argument can be used to see which predefined
groups of extensions are supported, and which extensions they cover.
=head2 --file=condition
If specified, indicates the C<Callable> that should return True to have a
file be included in the file selection process. The basename of the file
will be passed as the only argument. Defaults to C<True>, indicating that
all files should be included.
If C<--/file> is specified, then only directory paths will be accepted.
This only makes sense if C<--find> is also specified.
=head2 --file-separator-null
Flag. Indicate to separate filenames by null bytes rather than newlines
if the C<--files-with-matches> or C<--files-without-matches> option are
specified with a C<True> value.
=head2 --files-from=filename
Indicate the path of the file to read filenames from instead of the
expansion of paths from any positional arguments. "-" can be specified
to read filenames from STDIN.
=head2 --files-with-matches
Flag. If specified, will only produce the filenames of the files in which
the pattern was found. Defaults to C<False>.
=head2 --files-without-matches
Flag. If specified, will only produce the filenames of the files in which
the pattern was B<not> found. Defaults to C<False>.
=head2 --filesize=condition
If specified, indicates the C<Callable> that should return True to include a
file in the selection of files to be checked. The number of bytes of data
in the file, will be passed as the only argument. See also C<--is-empty>.
=begin code :lang<bash>
# show files that consist of at 30 bytes
$ rak --find --filesize='* >= 30'
=end code
=head2 --find
Flag. If specified, will B<not> look at the contents of the selected paths,
but instead consider the selected paths as lines in a virtual file. And as
such will always only produce filenames.
=head2 --only-first[=N]
Indicate the B<overall> number of matches to show. If specified without a
value, will default to B<1>. Defaults to B<1000> if a human is watching,
otherwise defaults to returning all possible matches. Can be used to tweak
search results, before letting it loose to get all possible results.
Special values that are allowed to produce all possible results are C<∞>
(aka C<221E INFINITY>), C<*> and C<Inf>.
=head2 --formula=[none]
Only applicable if C<--csv-per-line> has been specified. If specified,
indicates the action to be taken when a field starts with an equal sign
(indicating a formula of some kind in many spreadsheets). The following
values are recognized:
=item none - take not action, just pass on
=item die - throw an exception
=item diag - report line and position where formula was found
=item empty - replace the formula by an empty string
=head2 --frequencies
Flag. If specified, will produce a frequency table of the matches with
the most frequent match first. Default is C<False>. See also C<--unique>.
Usually used in conjunction with C<--matches-only> and/or C<Callable>
patterns returning something other than True/False/Nil/Empty.
=head2 --gid=condition
If specified, indicates the C<Callable> that should return True to include a
file in the selection of files to be checked. The numeric C<gid> of the file
will be passed as the only argument. Can also be specified as a single
numeric argument. See also C<--group>.
=begin code :lang<bash>
# show files of which the numeric group id is greater than 20
$ rak --find --gid='* > 20'
# show files of which the numeric group id is 20
$ rak --find --gid=20
=end code
NOTE: support of this feature depends on Raku supporting that feature on
the current operating system.
=head2 --group=condition
If specified, indicates the C<Callable> that should return True to include a
file in the selection of files to be checked. The name of the group
associated with the C<gid> of the file will be passed as the only argument.
Can also be specified as a list of comma separated names to (not) select on.
To select all names B<except> the listed named, prefix with a C<!>.
See also C<--gid>. Requires the
L<P5getgrnam|https://raku.land/zef:lizmat/P5getgrnam> module to be installed.
=begin code :lang<bash>
# files of which the name associated with the user id starts with underscore
$ rak --find --group='*.starts-with("_")'
# show files of which the group is "staff"
$ rak --find --group=staff
# show files of which the group is NOT "staff"
$ rak --find --group='!staff'
=end code
NOTE: support of this feature depends on Raku supporting that feature on
the current operating system.
=head2 --group-matches
Flag. Indicate whether matches of a file should be grouped together by
mentioning the filename only once (instead of on every line). Defaults
to C<True> if a human is watching, else C<False>.
=head2 --hard-links=condition
If specified, indicates the C<Callable> that should return True to include a
file in the selection of files to be checked. The number of hard-links to
the file on the filesystem, will be passed as the only argument.
=head2 --has-setgid