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