Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix option --[no-]json-translate #337

Merged
4 commits merged into from Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions lib/Zonemaster/CLI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ has 'json_translate' => (
traits => [ 'Getopt' ],
is => 'ro',
isa => 'Bool',
default => 0,
cmd_aliases => 'json_translate',
cmd_flag => 'json-translate',
documentation => __( 'Deprecated. Flag indicating if JSON output should include the translated message of the tag or not.' ),
Expand All @@ -97,7 +96,6 @@ has 'json_translate' => (
has 'raw' => (
is => 'rw',
isa => 'Bool',
default => 0,
documentation => __( 'Flag indicating if output should be translated to human language or dumped raw.' ),
);

Expand Down Expand Up @@ -368,28 +366,25 @@ sub run {
}

# errors and warnings
if ( $self->json_stream and not $self->json and grep( /^--no-json$/, @{ $self->ARGV } ) ) {
if ( $self->json_stream and not $self->json and grep( /^--no-?json$/, @{ $self->ARGV } ) ) {
die __( "Error: --json-stream and --no-json can't be used together." ) . "\n";
}

if ( $self->json_translate ) {
if ( defined $self->json_translate ) {
unless ( $self->json or $self->json_stream ) {
printf STDERR __( "Warning: --json-translate has no effect without either --json or --json-stream." ) . "\n";
}
printf STDERR __( "Warning: deprecated --json-translate, use --no-raw instead." ) . "\n";
}
else {
if ( grep( /^--no-json-translate$/, @{ $self->ARGV } ) ) {
unless ( $self->json or $self->json_stream ) {
printf STDERR __( "Warning: --json-translate has no effect without either --json or --json-stream." ) . "\n";
}
if ( $self->json_translate ) {
printf STDERR __( "Warning: deprecated --json-translate, use --no-raw instead." ) . "\n";
}
else {
printf STDERR __( "Warning: deprecated --no-json-translate, use --raw instead." ) . "\n";
}
}

# align values
$self->json( 1 ) if $self->json_stream;
$self->raw( 0 ) if $self->json_translate; # deprecated
$self->raw( $self->raw // ( defined $self->json_translate ? !$self->json_translate : 0 ) );

# Filehandle for diagnostics output
my $fh_diag = ( $self->json or $self->raw )
Expand Down
2 changes: 0 additions & 2 deletions script/zonemaster-cli
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ For streaming JSON output, include the translated message of the tag.
Print messages as raw dumps (message identifiers) instead of translating them
to human language.

Default: off

=item --[no-]time

Print the timestamp for each message.
Expand Down