Debian Codegraph @

lib/App/Yath/Command/help.pm

raw
1 package App::Yath::Command::help;
2 use strict;
3 use warnings;
4
5 use Test2::Util qw/pkg_to_file/;
6
7 our $VERSION = '1.000179';
8
9 use parent 'App::Yath::Command';
10 use Test2::Harness::Util::HashBase qw/<_command_info_hash/;
11
12 use Test2::Harness::Util qw/open_file find_libraries/;
13 use List::Util ();
14
15 sub options {};
16 sub group { '' }
17 sub summary { 'Show the list of commands' }
18
19 sub description {
20 return <<" EOT"
21 This command provides a list of commands when called with no arguments.
22 When given a command name as an argument it will print the help for that
23 command.
24 EOT
25 }
26
27 sub command_info_hash {
28 my $self = shift;
29
30 return $self->{+_COMMAND_INFO_HASH} if $self->{+_COMMAND_INFO_HASH};
31
32 my %commands;
33 my $command_libs = find_libraries('App::Yath::Command::*');
34 for my $lib (sort keys %$command_libs) {
35 my $ok = eval { require $command_libs->{$lib}; 1 };
36 unless ($ok) {
37 warn "Failed to load command '$command_libs->{$lib}': $@";
38 next;
39 }
40
41 next if $lib->internal_only;
42 my $name = $lib->name;
43 my $group = $lib->group;
44 $commands{$group}->{$name} = $lib->summary;
45 }
46
47 return $self->{+_COMMAND_INFO_HASH} = \%commands;
48 }
49
50 sub command_list {
51 my $self = shift;
52
53 my $command_hash = $self->command_info_hash();
54 my @commands = map keys %$_, values %$command_hash;
55 return @commands;
56 }
57
58 sub run {
59 my $self = shift;
60 my $args = $self->{+ARGS};
61
62 return $self->command_help($args->[0]) if @$args;
63
64 my $script = $self->settings->harness->script // $0;
65 my $maxlen = List::Util::max(map length, $self->command_list);
66
67 print "\nUsage: $script COMMAND [options]\n\nAvailable Commands:\n";
68
69 my $command_info_hash = $self->command_info_hash;
70 for my $group (sort keys %$command_info_hash) {
71 my $set = $command_info_hash->{$group};
72
73 printf(" %${maxlen}s: %s\n", $_, $set->{$_}) for sort keys %$set;
74 print "\n";
75 }
76
77 return 0;
78 }
79
80 sub command_help {
81 my $self = shift;
82 my ($command) = @_;
83
84 require App::Yath;
85 my $cmd_class = App::Yath->load_command($command);
86 print $cmd_class->cli_help(settings => $self->{+SETTINGS});
87
88 return 0;
89 }
90
91 1;
92
93 __END__
94
95 =pod
96
97 =encoding UTF-8
98
99 =head1 NAME
100
101 App::Yath::Command::help - Show the list of commands
102
103 =head1 DESCRIPTION
104
105 This command provides a list of commands when called with no arguments.
106 When given a command name as an argument it will print the help for that
107 command.
108
109
110 =head1 USAGE
111
112 $ yath [YATH OPTIONS] help [COMMAND OPTIONS]
113
114 =head2 YATH OPTIONS
115
116 =head3 Developer
117
118 =over 4
119
120 =item --dev-lib
121
122 =item --dev-lib=lib
123
124 =item -D
125
126 =item -D=lib
127
128 =item -Dlib
129
130 =item --no-dev-lib
131
132 Add paths to @INC before loading ANYTHING. This is what you use if you are developing yath or yath plugins to make sure the yath script finds the local code instead of the installed versions of the same code. You can provide an argument (-Dfoo) to provide a custom path, or you can just use -D without and arg to add lib, blib/lib and blib/arch.
133
134 Can be specified multiple times
135
136
137 =back
138
139 =head3 Environment
140
141 =over 4
142
143 =item --persist-dir ARG
144
145 =item --persist-dir=ARG
146
147 =item --no-persist-dir
148
149 Where to find persistence files.
150
151
152 =item --persist-file ARG
153
154 =item --persist-file=ARG
155
156 =item --pfile ARG
157
158 =item --pfile=ARG
159
160 =item --no-persist-file
161
162 Where to find the persistence file. The default is /{system-tempdir}/project-yath-persist.json. If no project is specified then it will fall back to the current directory. If the current directory is not writable it will default to /tmp/yath-persist.json which limits you to one persistent runner on your system.
163
164
165 =item --project ARG
166
167 =item --project=ARG
168
169 =item --project-name ARG
170
171 =item --project-name=ARG
172
173 =item --no-project
174
175 This lets you provide a label for your current project/codebase. This is best used in a .yath.rc file. This is necessary for a persistent runner.
176
177
178 =back
179
180 =head3 Help and Debugging
181
182 =over 4
183
184 =item --show-opts
185
186 =item --no-show-opts
187
188 Exit after showing what yath thinks your options mean
189
190
191 =item --version
192
193 =item -V
194
195 =item --no-version
196
197 Exit after showing a helpful usage message
198
199
200 =back
201
202 =head3 Plugins
203
204 =over 4
205
206 =item --no-scan-plugins
207
208 =item --no-no-scan-plugins
209
210 Normally yath scans for and loads all App::Yath::Plugin::* modules in order to bring in command-line options they may provide. This flag will disable that. This is useful if you have a naughty plugin that is loading other modules when it should not.
211
212
213 =item --plugins PLUGIN
214
215 =item --plugins +App::Yath::Plugin::PLUGIN
216
217 =item --plugins PLUGIN=arg1,arg2,...
218
219 =item --plugin PLUGIN
220
221 =item --plugin +App::Yath::Plugin::PLUGIN
222
223 =item --plugin PLUGIN=arg1,arg2,...
224
225 =item -pPLUGIN
226
227 =item --no-plugins
228
229 Load a yath plugin.
230
231 Can be specified multiple times
232
233
234 =back
235
236 =head2 COMMAND OPTIONS
237
238 =head3 Cover Options
239
240 =over 4
241
242 =item --cover-aggregator ByTest
243
244 =item --cover-aggregator ByRun
245
246 =item --cover-aggregator +Custom::Aggregator
247
248 =item --cover-agg ByTest
249
250 =item --cover-agg ByRun
251
252 =item --cover-agg +Custom::Aggregator
253
254 =item --no-cover-aggregator
255
256 Choose a custom aggregator subclass
257
258
259 =item --cover-class ARG
260
261 =item --cover-class=ARG
262
263 =item --no-cover-class
264
265 Choose a Test2::Plugin::Cover subclass
266
267
268 =item --cover-dirs ARG
269
270 =item --cover-dirs=ARG
271
272 =item --cover-dir ARG
273
274 =item --cover-dir=ARG
275
276 =item --no-cover-dirs
277
278 NO DESCRIPTION - FIX ME
279
280 Can be specified multiple times
281
282
283 =item --cover-exclude-dirs ARG
284
285 =item --cover-exclude-dirs=ARG
286
287 =item --cover-exclude-dir ARG
288
289 =item --cover-exclude-dir=ARG
290
291 =item --no-cover-exclude-dirs
292
293 Directory to leave out of file coverage and coverage metrics, along with everything under it at any depth. May be specified multiple times. Wildcards are expanded when the option is parsed, so a pattern matching nothing excludes nothing. Values are word-split first, so a path containing whitespace must be quoted or backslash-escaped. A resolved path may not contain a comma.
294
295 Can be specified multiple times
296
297
298 =item --cover-exclude-private
299
300 =item --no-cover-exclude-private
301
302
303
304
305 =item --cover-files
306
307 =item --no-cover-files
308
309 Use Test2::Plugin::Cover to collect coverage data for what files are touched by what tests. Unlike Devel::Cover this has very little performance impact (About 4% difference)
310
311
312 =item --cover-from path/to/log.jsonl
313
314 =item --cover-from http://example.com/coverage
315
316 =item --cover-from path/to/coverage.jsonl
317
318 =item --no-cover-from
319
320 This can be a test log, a coverage dump (old style json or new jsonl format), or a url to any of the previous. Tests will not be run if the file/url is invalid.
321
322
323 =item --cover-from-type json
324
325 =item --cover-from-type jsonl
326
327 =item --cover-from-type log
328
329 =item --no-cover-from-type
330
331 File type for coverage source. Usually it can be detected, but when it cannot be you should specify. "json" is old style single-blob coverage data, "jsonl" is the new by-test style, "log" is a logfile from a previous run.
332
333
334 =item --cover-manager My::Coverage::Manager
335
336 =item --no-cover-manager
337
338 Coverage 'from' manager to use when coverage data does not provide one
339
340
341 =item --cover-maybe-from path/to/log.jsonl
342
343 =item --cover-maybe-from http://example.com/coverage
344
345 =item --cover-maybe-from path/to/coverage.jsonl
346
347 =item --no-cover-maybe-from
348
349 This can be a test log, a coverage dump (old style json or new jsonl format), or a url to any of the previous. Tests will continue even if the coverage file/url is invalid.
350
351
352 =item --cover-maybe-from-type json
353
354 =item --cover-maybe-from-type jsonl
355
356 =item --cover-maybe-from-type log
357
358 =item --no-cover-maybe-from-type
359
360 Same as "from_type" but for "maybe_from". Defaults to "from_type" if that is specified, otherwise auto-detect
361
362
363 =item --cover-metrics
364
365 =item --no-cover-metrics
366
367
368
369
370 =item --cover-types ARG
371
372 =item --cover-types=ARG
373
374 =item --cover-type ARG
375
376 =item --cover-type=ARG
377
378 =item --no-cover-types
379
380 NO DESCRIPTION - FIX ME
381
382 Can be specified multiple times
383
384
385 =item --cover-write
386
387 =item --cover-write=coverage.jsonl
388
389 =item --cover-write=coverage.json
390
391 =item --no-cover-write
392
393 Create a json or jsonl file of all coverage data seen during the run (This implies --cover-files).
394
395
396 =back
397
398 =head3 Git Options
399
400 =over 4
401
402 =item --git-change-base master
403
404 =item --git-change-base HEAD^
405
406 =item --git-change-base df22abe4
407
408 =item --no-git-change-base
409
410 Find files changed by all commits in the current branch from most recent stopping when a commit is found that is also present in the history of the branch/commit specified as the change base.
411
412
413 =back
414
415 =head3 Help and Debugging
416
417 =over 4
418
419 =item --dummy
420
421 =item -d
422
423 =item --no-dummy
424
425 Dummy run, do not actually execute anything
426
427 Can also be set with the following environment variables: C<T2_HARNESS_DUMMY>
428
429
430 =item --help
431
432 =item -h
433
434 =item --no-help
435
436 exit after showing help information
437
438
439 =item --interactive
440
441 =item -i
442
443 =item --no-interactive
444
445 Use interactive mode, 1 test at a time, stdin forwarded to it
446
447
448 =item --keep-dirs
449
450 =item --keep_dir
451
452 =item -k
453
454 =item --no-keep-dirs
455
456 Do not delete directories when done. This is useful if you want to inspect the directories used for various commands.
457
458
459 =item --procname-prefix ARG
460
461 =item --procname-prefix=ARG
462
463 =item --no-procname-prefix
464
465 Add a prefix to all proc names (as seen by ps).
466
467
468 =back
469
470 =head3 YathUI Options
471
472 =over 4
473
474 =item --yathui-api-key ARG
475
476 =item --yathui-api-key=ARG
477
478 =item --no-yathui-api-key
479
480 Yath-UI API key. This is not necessary if your Yath-UI instance is set to single-user
481
482
483 =item --yathui-grace
484
485 =item --no-yathui-grace
486
487 If yath cannot connect to yath-ui it normally throws an error, use this to make it fail gracefully. You get a warning, but things keep going.
488
489
490 =item --yathui-long-duration 10
491
492 =item --no-yathui-long-duration
493
494 Minimum duration length (seconds) before a test goes from MEDIUM to LONG
495
496
497 =item --yathui-medium-duration 5
498
499 =item --no-yathui-medium-duration
500
501 Minimum duration length (seconds) before a test goes from SHORT to MEDIUM
502
503
504 =item --yathui-mode summary
505
506 =item --yathui-mode qvf
507
508 =item --yathui-mode qvfd
509
510 =item --yathui-mode complete
511
512 =item --no-yathui-mode
513
514 Set the upload mode (default 'qvfd')
515
516
517 =item --yathui-project ARG
518
519 =item --yathui-project=ARG
520
521 =item --no-yathui-project
522
523 The Yath-UI project for your test results
524
525
526 =item --yathui-retry
527
528 =item --no-yathui-retry
529
530 How many times to try an operation before giving up
531
532 Can be specified multiple times
533
534
535 =item --yathui-url http://my-yath-ui.com/...
536
537 =item --uri http://my-yath-ui.com/...
538
539 =item --no-yathui-url
540
541 Yath-UI url
542
543
544 =back
545
546 =head1 SOURCE
547
548 The source code repository for Test2-Harness can be found at
549 F<http://github.com/Test-More/Test2-Harness/>.
550
551 =head1 MAINTAINERS
552
553 =over 4
554
555 =item Chad Granum E<lt>[email protected]<gt>
556
557 =back
558
559 =head1 AUTHORS
560
561 =over 4
562
563 =item Chad Granum E<lt>[email protected]<gt>
564
565 =back
566
567 =head1 COPYRIGHT
568
569 Copyright 2026 Chad Granum E<lt>[email protected]<gt>.
570
571 This program is free software; you can redistribute it and/or
572 modify it under the same terms as Perl itself.
573
574 See F<http://dev.perl.org/licenses/>
575
576 =cut
577