Skip to content

Commit

Permalink
Merge pull request #157 from vlevigneron/fix-issue-zonemaster-engine-578
Browse files Browse the repository at this point in the history
Related to zonemaster-engine issue 578
  • Loading branch information
vlevigneron authored Oct 12, 2020
2 parents 3ac506d + 94a9c69 commit 9823b13
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
48 changes: 37 additions & 11 deletions lib/Zonemaster/CLI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ extends 'Zonemaster::Engine::Exception';
# The actual interesting module.
package Zonemaster::CLI;

use version; our $VERSION = version->declare("v2.0.5");

use 5.014002;

use strict;
use warnings;

use version; our $VERSION = version->declare( "v2.0.7" );

use Locale::TextDomain 'Zonemaster-CLI';
use Moose;
with 'MooseX::Getopt';
Expand Down Expand Up @@ -112,6 +114,13 @@ has 'show_module' => (
default => 0,
);

has 'show_testcase' => (
is => 'ro',
isa => 'Bool',
documentation => __( 'Print the name of the test case on entries.' ),
default => 0,
);

has 'ns' => (
is => 'ro',
isa => 'ArrayRef',
Expand Down Expand Up @@ -322,11 +331,11 @@ sub run {

if ( $self->profile ) {
say $fh_diag __x( "Loading profile from {path}.", path => $self->profile );
my $json = read_file( $self->profile );
my $foo = Zonemaster::Engine::Profile->from_json( $json );
my $profile = Zonemaster::Engine::Profile->default;
$profile->merge( $foo );
Zonemaster::Engine::Profile->effective->merge( $profile );
my $json = read_file( $self->profile );
my $foo = Zonemaster::Engine::Profile->from_json( $json );
my $profile = Zonemaster::Engine::Profile->default;
$profile->merge( $foo );
Zonemaster::Engine::Profile->effective->merge( $profile );
}
else {

Expand Down Expand Up @@ -402,13 +411,18 @@ sub run {
printf "%-12s ", $entry->module;
}

if ( $self->show_testcase ) {
printf "%-14s ", $entry->testcase;
}

say $translator->translate_tag( $entry );
}
elsif ( $self->json_stream ) {
my %r;

$r{timestamp} = $entry->timestamp;
$r{module} = $entry->module;
$r{testcase} = $entry->testcase;
$r{tag} = $entry->tag;
$r{level} = $entry->level;
$r{args} = $entry->args if $entry->args;
Expand All @@ -419,11 +433,17 @@ sub run {
elsif ( $self->json ) {
# Don't do anything
}
elsif ( $self->show_module ) {
printf "%7.2f %-9s %-12s %s\n", $entry->timestamp, $entry->level, $entry->module, $entry->string;
}
else {
printf "%7.2f %-9s %s\n", $entry->timestamp, $entry->level, $entry->string;
my $str = sprintf "%7.2f %-9s ", $entry->timestamp, $entry->level;
if ( $self->show_module ) {
$str.= sprintf "%-12s ", $entry->module;
}
if ( $self->show_testcase ) {
$str.= sprintf "%-14s ", $entry->testcase;
}
my $entry_str = sprintf "%s", $entry->string;
$entry_str =~ s/^([A-Z0-9]+:)*//;
printf "%s%s\n", $str, $entry_str;
}
} ## end if ( $numeric{ uc $entry...})
if ( $self->stop_level and $numeric{ uc $entry->level } >= $numeric{ $self->stop_level } ) {
Expand Down Expand Up @@ -452,6 +472,9 @@ sub run {
if ( $self->show_module ) {
print __( 'Module ' );
}
if ( $self->show_testcase ) {
print __( 'Testcase ' );
}
say __( 'Message' );

if ( $self->time ) {
Expand All @@ -463,6 +486,9 @@ sub run {
if ( $self->show_module ) {
print __( '============ ' );
}
if ( $self->show_testcase ) {
print __( '============== ' );
}
say __( '=======' );
} ## end if ( $translator )

Expand Down
4 changes: 4 additions & 0 deletions script/zonemaster-cli
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ Turn the printing of the message severity level on or off (default on).

Turn the printing of which module produced a message on or off (default off).

=item --show_testcase, --no-show_testcase

Turn the printing of which test case produced a message on or off (default off).

=item --ns=NAME[/IP]

Provide information about a nameserver, for undelegated tests. The argument
Expand Down

0 comments on commit 9823b13

Please sign in to comment.