Debian Codegraph @

lib/App/Yath/Options/Display.pm

raw
1 package App::Yath::Options::Display;
2 use strict;
3 use warnings;
4
5 our $VERSION = '1.000179';
6
7 use Test2::Harness::Util qw/mod2file/;
8
9 use App::Yath::Options;
10
11 option_group {prefix => 'display', category => "Display Options"} => sub {
12 option color => (
13 description => "Turn color on, default is true if STDOUT is a TTY.",
14 default => sub { -t STDOUT ? 1 : 0 },
15 );
16
17 option quiet => (
18 short => 'q',
19 type => 'c',
20 description => "Be very quiet.",
21 default => 0,
22 );
23
24 option verbose => (
25 short => 'v',
26 type => 'c',
27 description => "Be more verbose",
28 default => 0,
29 );
30
31 option no_wrap => (
32 type => 'b',
33 description => "Do not do fancy text-wrapping, let the terminal handle it",
34 default => 0,
35 );
36
37 option no_final_table => (
38 type => 'b',
39 description => "When printing final results, don't use table-style display",
40 default => 0,
41 );
42
43 option show_times => (
44 short => 'T',
45 description => 'Show the timing data for each job',
46 );
47
48 option hide_runner_output => (
49 description => 'Hide output from the runner, showing only test output. (See Also truncate_runner_output)',
50 default => 0,
51 );
52
53 option truncate_runner_output => (
54 description => 'Only show runner output that was generated after the current command. This is only useful with a persistent runner.',
55 default => 0,
56 );
57
58 option term_width => (
59 type => 's',
60 alt => ['term-size'],
61 description => 'Alternative to setting $TABLE_TERM_SIZE. Setting this will override the terminal width detection to the number of characters specified.',
62 long_examples => [' 80', ' 200'],
63
64 action => sub {
65 my ($prefix, $field, $raw, $norm, $slot, $settings, $handler) = @_;
66 $ENV{TABLE_TERM_SIZE} = $norm;
67 },
68 );
69
70 option 'progress' => (
71 default => sub { -t STDOUT ? 1 : 0 },
72
73 description => "Toggle progress indicators. On by default if STDOUT is a TTY. You can use --no-progress to disable the 'events seen' counter and buffered event pre-display",
74 );
75
76 option renderers => (
77 alt => ['renderer'],
78 type => 'H',
79
80 description => 'Specify renderers, (Default: "Formatter=Test2"). Use "+" to give a fully qualified module name. Without "+" "Test2::Harness::Renderer::" will be prepended to your argument.',
81
82 long_examples => [' +My::Renderer', ' Renderer=arg1,arg2,...'],
83 short_examples => [' +My::Renderer', ' Renderer=arg1,arg2,...'],
84
85 action => sub {
86 my ($prefix, $field, $raw, $norm, $slot, $settings, $handler) = @_;
87
88 my ($class, $args) = @$norm;
89
90 $class = "Test2::Harness::Renderer::$class"
91 unless $class =~ s/^\+//;
92
93 my $file = mod2file($class);
94 my $ok = eval { require $file; 1 };
95 warn "Failed to load renderer '$class': $@" unless $ok;
96
97 $handler->($slot, [$class, $args]);
98 },
99 );
100
101 post 100 => sub {
102 my %params = @_;
103 my $settings = $params{settings};
104
105 my $display = $settings->display;
106 my $renderers = $display->renderers;
107
108 my $quiet = $display->quiet;
109 my $verbose = $display->verbose;
110
111 die "The 'quiet' and 'verbose' options may not be used together.\n"
112 if $verbose && $quiet;
113
114 if ($quiet) {
115 delete $renderers->{'Test2::Harness::Renderer::Formatter'};
116 @{$renderers->{'@'}} = grep { $_ ne 'Test2::Harness::Renderer::Formatter' } @{$renderers->{'@'}};
117 return;
118 }
119
120 my @args = map { $_ => $settings->formatter->$_ } qw{
121 formatter
122 show_run_info
123 show_job_info
124 show_job_launch
125 show_job_end
126 };
127
128 push @args => map { $_ => $settings->display->$_ } qw{
129 progress
130 color
131 quiet
132 verbose
133 show_times
134 };
135
136 if (my $formatter_args = $renderers->{'Test2::Harness::Renderer::Formatter'}) {
137 @$formatter_args = @args unless @$formatter_args;
138 return;
139 }
140
141 return if $renderers->{'@'} && @{$renderers->{'@'}};
142
143 push @{$renderers->{'@'}} => 'Test2::Harness::Renderer::Formatter';
144 $renderers->{'Test2::Harness::Renderer::Formatter'} = \@args;
145 };
146 };
147
148 option_group {prefix => 'formatter', category => "Formatter Options"} => sub {
149 option formatter => (
150 type => 's',
151 );
152
153 option 'qvf' => (
154 description => '[Q]uiet, but [V]erbose on [F]ailure. Hide all output from tests when they pass, except to say they passed. If a test fails then ALL output from the test is verbosely output.',
155 );
156
157 option show_job_end => (
158 description => 'Show output when a job ends. (Default: on)',
159 default => 1,
160 );
161
162 option show_job_info => (
163 description => 'Show the job configuration when a job starts. (Default: off, unless -vv)',
164 default => 0,
165 );
166
167 option show_job_launch => (
168 description => "Show output for the start of a job. (Default: off unless -v)",
169 default => 0,
170 );
171
172 option show_run_info => (
173 description => 'Show the run configuration when a run starts. (Default: off, unless -vv)',
174 default => 0,
175 );
176
177 post 90 => sub {
178 my %params = @_;
179 my $settings = $params{settings};
180
181 $settings->formatter->field(formatter => $settings->formatter->qvf ? 'QVF' : 'Test2')
182 unless defined $settings->formatter->formatter;
183
184 $settings->formatter->field(show_job_launch => 1)
185 if $settings->display->verbose > 0;
186
187 if ($settings->display->verbose > 1) {
188 $settings->formatter->field(show_job_info => 1);
189 $settings->formatter->field(show_run_info => 1);
190 }
191 };
192 };
193
194 1;
195
196 __END__
197
198
199 =pod
200
201 =encoding UTF-8
202
203 =head1 NAME
204
205 App::Yath::Options::Display - Display options for Yath.
206
207 =head1 DESCRIPTION
208
209 This is where display options are defined.
210
211 =head1 PROVIDED OPTIONS
212
213 =head2 COMMAND OPTIONS
214
215 =head3 Display Options
216
217 =over 4
218
219 =item --color
220
221 =item --no-color
222
223 Turn color on, default is true if STDOUT is a TTY.
224
225
226 =item --hide-runner-output
227
228 =item --no-hide-runner-output
229
230 Hide output from the runner, showing only test output. (See Also truncate_runner_output)
231
232
233 =item --no-final-table
234
235 =item --no-no-final-table
236
237 When printing final results, don't use table-style display
238
239
240 =item --no-wrap
241
242 =item --no-no-wrap
243
244 Do not do fancy text-wrapping, let the terminal handle it
245
246
247 =item --progress
248
249 =item --no-progress
250
251 Toggle progress indicators. On by default if STDOUT is a TTY. You can use --no-progress to disable the 'events seen' counter and buffered event pre-display
252
253
254 =item --quiet
255
256 =item -q
257
258 =item --no-quiet
259
260 Be very quiet.
261
262 Can be specified multiple times
263
264
265 =item --renderers +My::Renderer
266
267 =item --renderers Renderer=arg1,arg2,...
268
269 =item --renderer +My::Renderer
270
271 =item --renderer Renderer=arg1,arg2,...
272
273 =item --no-renderers
274
275 Specify renderers, (Default: "Formatter=Test2"). Use "+" to give a fully qualified module name. Without "+" "Test2::Harness::Renderer::" will be prepended to your argument.
276
277 Can be specified multiple times. If the same key is listed multiple times the value lists will be appended together.
278
279
280 =item --show-times
281
282 =item -T
283
284 =item --no-show-times
285
286 Show the timing data for each job
287
288
289 =item --term-width 80
290
291 =item --term-width 200
292
293 =item --term-size 80
294
295 =item --term-size 200
296
297 =item --no-term-width
298
299 Alternative to setting $TABLE_TERM_SIZE. Setting this will override the terminal width detection to the number of characters specified.
300
301
302 =item --truncate-runner-output
303
304 =item --no-truncate-runner-output
305
306 Only show runner output that was generated after the current command. This is only useful with a persistent runner.
307
308
309 =item --verbose
310
311 =item -v
312
313 =item --no-verbose
314
315 Be more verbose
316
317 Can be specified multiple times
318
319
320 =back
321
322 =head3 Formatter Options
323
324 =over 4
325
326 =item --formatter ARG
327
328 =item --formatter=ARG
329
330 =item --no-formatter
331
332 NO DESCRIPTION - FIX ME
333
334
335 =item --qvf
336
337 =item --no-qvf
338
339 [Q]uiet, but [V]erbose on [F]ailure. Hide all output from tests when they pass, except to say they passed. If a test fails then ALL output from the test is verbosely output.
340
341
342 =item --show-job-end
343
344 =item --no-show-job-end
345
346 Show output when a job ends. (Default: on)
347
348
349 =item --show-job-info
350
351 =item --no-show-job-info
352
353 Show the job configuration when a job starts. (Default: off, unless -vv)
354
355
356 =item --show-job-launch
357
358 =item --no-show-job-launch
359
360 Show output for the start of a job. (Default: off unless -v)
361
362
363 =item --show-run-info
364
365 =item --no-show-run-info
366
367 Show the run configuration when a run starts. (Default: off, unless -vv)
368
369
370 =back
371
372 =head1 SOURCE
373
374 The source code repository for Test2-Harness can be found at
375 F<http://github.com/Test-More/Test2-Harness/>.
376
377 =head1 MAINTAINERS
378
379 =over 4
380
381 =item Chad Granum E<lt>[email protected]<gt>
382
383 =back
384
385 =head1 AUTHORS
386
387 =over 4
388
389 =item Chad Granum E<lt>[email protected]<gt>
390
391 =back
392
393 =head1 COPYRIGHT
394
395 Copyright 2020 Chad Granum E<lt>[email protected]<gt>.
396
397 This program is free software; you can redistribute it and/or
398 modify it under the same terms as Perl itself.
399
400 See F<http://dev.perl.org/licenses/>
401
402 =cut