File: usage.wrapper.pl

package info (click to toggle)
zonemaster-cli 8.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 512 kB
  • sloc: perl: 3,288; makefile: 17
file content (86 lines) | stat: -rwxr-xr-x 2,087 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env perl
use v5.16;
use warnings;

use File::Basename        qw( dirname );
use File::Spec::Functions qw( catfile );
use Zonemaster::CLI;
use Zonemaster::Engine::Nameserver;
use Zonemaster::Engine::Profile;

use lib catfile( dirname( dirname( __FILE__ ) ), 'script' );

# Help Zonemaster::CLI find zonemaster-cli in test context
$Zonemaster::CLI::SCRIPT = catfile( dirname( dirname( __FILE__ ) ), 'script', 'zonemaster-cli' );
$Zonemaster::CLI::SCRIPT = '/usr/bin/zonemaster-cli' if $ENV{AUTOPKGTEST_TMP};

# Parse command line options upto and including '--'.

my $opt_record = 0;
my $opt_datafile;
while ( @ARGV ) {
    my $arg = shift @ARGV;
    if ( substr( $arg, 0, 2 ) eq '--' ) {
        if ( $arg eq '--' ) {
            last;
        }
        elsif ( $arg eq '--record' ) {
            $opt_record = 1;
        }
        else {
            die "unrecognized option '$arg'";
        }
    }
    else {
        if ( defined $opt_datafile ) {
            die "too many data files provided";
        }
        $opt_datafile = $arg;
    }
} ## end while ( @ARGV )

if ( $opt_record && !defined $opt_datafile ) {
    die "must not specify --record without also specifying a data file";
}

# Prime Zonemaster Engine before letting zonemaster-cli do its thing

if ( !$opt_record ) {
    Zonemaster::Engine::Profile->effective->set( q{no_network}, 1 );
}

if ( $opt_datafile ) {
    Zonemaster::Engine::Nameserver->restore( $opt_datafile );
}

our $EXIT_STATUS;
our $EMITTED_WARNING = 0;
do {
    # Intercept warn()
    local $SIG{__WARN__} = sub {
        print STDERR "__WARN__: " . $_[0];
        $EMITTED_WARNING = 1;
    };

    # Run Zonemaster::CLI
    eval {
        $EXIT_STATUS = Zonemaster::CLI->run( @ARGV );
        1;
    } or do {
        print STDERR $@;
        $EXIT_STATUS = $Zonemaster::CLI::EXIT_GENERIC_ERROR;
    };
};

# Wrap up and terminate

if ( $opt_record ) {
    Zonemaster::Engine::Nameserver->save( $opt_datafile );
}

if ( $EMITTED_WARNING ) {
    say STDERR "EXIT 125: one or more warnings were emitted";
    exit 125;
}

exit $EXIT_STATUS;