| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use File::Basename; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use RackMan; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use RackMan::Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Term::ANSIColor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | $::PROGRAM = "RackManager"; | |||||||||||||||||||||||||||
| 13 | 1 | $::VERSION = RackMan->VERSION; | |||||||||||||||||||||||||||
| 14 | 1 | $::COMMAND = basename($0); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | # | ||||||||||||||||||||||||||||
| 18 | # main | ||||||||||||||||||||||||||||
| 19 | # | ||||||||||||||||||||||||||||
| 20 | MAIN: { | ||||||||||||||||||||||||||||
| 21 | 1 | ▶ | if (not caller()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 0 | run(); | |||||||||||||||||||||||||||
| 23 | 0 | exit RackMan->status; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # | ||||||||||||||||||||||||||||
| 29 | # run() | ||||||||||||||||||||||||||||
| 30 | # --- | ||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||
| 32 | # detect if stdout is connected to a terminal | ||||||||||||||||||||||||||||
| 33 | 0 | ▶ | (-t STDOUT ? $Term::ANSIColor::AUTORESET : $ENV{ANSI_COLORS_DISABLED}) = 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 0 | $|++; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # default options | ||||||||||||||||||||||||||||
| 37 | 0 | my %options = ( | |||||||||||||||||||||||||||
| 38 | config => "/etc/rack.conf", | ||||||||||||||||||||||||||||
| 39 | scm => 1, | ||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # parse options | ||||||||||||||||||||||||||||
| 43 | 0 | Getopt::Long::Configure(qw< no_auto_abbrev no_ignore_case >); | |||||||||||||||||||||||||||
| 44 | 0 | ▶ | GetOptions(\%options, qw{ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | help|usage|h! man! version|V! | ||||||||||||||||||||||||||||
| 46 | verbose|v! config|c=s scm|S! | ||||||||||||||||||||||||||||
| 47 | formats|F=s only_formats|only-formats|G=s | ||||||||||||||||||||||||||||
| 48 | no_write_dev_cfg|no-write-device-config | ||||||||||||||||||||||||||||
| 49 | device_login|device-login=s device_password|device-password=s | ||||||||||||||||||||||||||||
| 50 | read_community|read-community=s write_community|write-community=s | ||||||||||||||||||||||||||||
| 51 | template|t=s output|o=s | ||||||||||||||||||||||||||||
| 52 | dhcp_template|dhcp-template=s | ||||||||||||||||||||||||||||
| 53 | kickstart_template|kickstart-template|ks=s | ||||||||||||||||||||||||||||
| 54 | pxe_template|pxe-template=s | ||||||||||||||||||||||||||||
| 55 | }) or pod2usage(0); | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # handle --version, --usage and --help | ||||||||||||||||||||||||||||
| 58 | 0 | ▶ | $options{man} and pod2usage(2); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | $options{help} and pod2usage(1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | $options{version} and print "$::PROGRAM v$::VERSION\n" and exit; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$options{"version"} and print "$main::PROGRAM v$main::VERSION\n"
MC/DC0%0/2
$options{"version"} and print "$main::PROGRAM v$main::VERSION\n"
$options{"version"}
print "$main::PROGRAM v$main::VERSION\n"
Truth table0%0/3
A and B
A= $options{"version"}B= print "$main::PROGRAM v$main::VERSION\n"
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | # if there's no argument, print the usage | ||||||||||||||||||||||||||||
| 63 | 0 | ▶ | pod2usage(1) if @ARGV == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | # handle some specific options | ||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ($options{only_formats}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | $options{formats} = $options{only_formats}; | |||||||||||||||||||||||||||
| 68 | 0 | $options{no_write_dev_cfg} = 1; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # read configuration file | ||||||||||||||||||||||||||||
| 72 | 0 | my $config = RackMan::Config->new(-file => $options{config}); | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | # instanciate the backend object | ||||||||||||||||||||||||||||
| 75 | 0 | my $rackman = RackMan->new({ options => \%options, config => $config }); | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # process the command | ||||||||||||||||||||||||||||
| 78 | 0 | $rackman->process(@ARGV); | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | # | ||||||||||||||||||||||||||||
| 83 | # pod2usage() | ||||||||||||||||||||||||||||
| 84 | # --------- | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub pod2usage { | ||||||||||||||||||||||||||
|
Subroutine
pod2usage: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 86 | 0 | my ($n) = @_; | |||||||||||||||||||||||||||
| 87 | 0 | require Pod::Usage; | |||||||||||||||||||||||||||
| 88 | 0 | Pod::Usage::pod2usage({ -exitval => 0, -verbose => $n, -noperldoc => 1 }); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 1 | 1 | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | __END__ | ||||||||||||||||||||||||||||