| 1 | # | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | package Rex::CLI; | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 15 | ▶ | use v5.14.4; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 15 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 15 | our $VERSION = '1.16.1'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 15 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 15 | ▶ | use FindBin; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 15 | ▶ | use File::Basename qw(basename dirname); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 15 | ▶ | use Time::HiRes qw(gettimeofday tv_interval); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 15 | ▶ | use Cwd qw(getcwd); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 15 | ▶ | use List::Util qw(max); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 15 | ▶ | use Text::Wrap; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 15 | ▶ | use Term::ANSIColor; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 15 | ▶ | use Term::ReadKey; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 15 | ▶ | use Sort::Naturally; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 15 | ▶ | use if $OSNAME eq 'MSWin32', 'Win32::Console::ANSI'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 15 | ▶ | use Rex; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 15 | ▶ | use Rex::Args; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 15 | ▶ | use Rex::Config; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 15 | ▶ | use Rex::Group; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 15 | ▶ | use Rex::Batch; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 15 | ▶ | use Rex::TaskList; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 15 | ▶ | use Rex::Logger; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 15 | ▶ | use YAML; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 15 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 15 | my $no_color = 0; | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | # preload some modules | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 15 | ▶ | use Rex -base; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 15 | $OUTPUT_AUTOFLUSH++; | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 15 | my ( %opts, @help, @exit ); | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 15 | ▶ | if ( $#ARGV < 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 15 | @ARGV = qw(-h); | |||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my $that = shift; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | my $proto = ref($that) || $that; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $that || $that
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table0%0/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my $self = {@_}; | |||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | bless( $self, $proto ); | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub __run__ { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__run__: not called CC=65 SCAR=83.6
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my ( $self, %more_args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | Rex::Args->parse_rex_opts; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | %opts = Rex::Args->getopts; | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if ( $opts{'Q'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | my $stdout; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | open( my $newout, '>', \$stdout ); | |||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | select $newout; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | close(STDERR); | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if ( $opts{'m'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $no_color = 1; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $Rex::Logger::no_color = 1; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if ( $opts{'d'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | $Rex::Logger::debug = $opts{'d'}; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $Rex::Logger::silent = 0; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | Rex::Config->set_use_cache(1); | |||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if ( $opts{"c"} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | # Rex::Config->set_use_cache(1); | ||||||||||||||||||||||||||||||||||||||||||
| 86 | # since 0.46 just a pseudo option | ||||||||||||||||||||||||||||||||||||||||||
| 87 | # cache is enabled by default | ||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | elsif ( $opts{"C"} ) { | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | Rex::Config->set_use_cache(0); | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | Rex::Logger::debug("This is Rex version: $Rex::VERSION"); | |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | Rex::Logger::debug("Command Line Parameters"); | |||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | for my $param ( keys %opts ) { | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | Rex::Logger::debug( "\t$param = " . $opts{$param} ); | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if ( $opts{'h'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $self->__help__; | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | ▶ | elsif ( $opts{'v'} && !$opts{'T'} ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$opts{"v"} and not $opts{"T"}
MC/DC0%0/2
$opts{"v"} and not $opts{"T"}
$opts{"v"}
not $opts{"T"}
Truth table0%0/3
A and not(B)
A= $opts{"v"}B= not $opts{"T"}
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $self->__version__; | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if ( $opts{'q'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $::QUIET = 1; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | if ( $opts{'w'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $::QUIET = 2; | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $::rexfile = "Rexfile"; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | if ( $opts{'f'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | Rex::Logger::debug( "Using Rexfile: " . $opts{'f'} ); | |||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | $::rexfile = $opts{'f'}; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | if ( ( !-e $::rexfile ) && ( $ARGV[0] && $ARGV[0] =~ /:/ ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not -e $main::rexfile and ($ARGV[0] and $ARGV[0] =~ /:/u)
$ARGV[0] and $ARGV[0] =~ /:/u
MC/DC0%0/3
not -e $main::rexfile and ($ARGV[0] and $ARGV[0] =~ /:/u)
not -e $main::rexfile
$ARGV[0]
$ARGV[0] =~ /:/u
Truth table0%0/4
not(A) and B and C
A= not -e $main::rexfileB= $ARGV[0]C= $ARGV[0] =~ /:/u
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | #if there is no Rexfile, and the user asks for a longer path task, see if we can use it as the Rexfile | ||||||||||||||||||||||||||||||||||||||||||
| 122 | #eg: rex -H $host Misc:Example:prepare --bar=baz | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $::rexfile = $ARGV[0]; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $::rexfile =~ s/:[^:]*$//; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | $::rexfile =~ s{:}{/}g; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $::rexfile = 'Rex/' . $::rexfile . '.pm'; | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | FORCE_SERVER: { | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | if ( $opts{'H'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | if ( $opts{'H'} =~ m/^perl:(.*)/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | my $host_eval = eval($1); | |||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if ( ref($host_eval) eq "ARRAY" ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $::FORCE_SERVER = join( " ", @{$host_eval} ); | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | die("Perl Code have to return an array reference."); | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $::FORCE_SERVER = $opts{'H'}; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if ( $opts{'z'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | my $host_eval = eval { `$opts{'z'}`; }; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | if ( $host_eval =~ m/\S/xms ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | $::FORCE_SERVER = join( " ", split /\n|,|;/, $host_eval ); | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | $::FORCE_SERVER = $opts{'H'}; | |||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | if ( $opts{'z'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | my $host_eval = eval { `$opts{'z'}`; }; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | if ( $host_eval =~ m/\S/xms ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $::FORCE_SERVER = join( " ", split /\n|,|;/, $host_eval ); | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | Rex::Logger::info("You must give a valid command."); | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | if ( $opts{'o'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | Rex::Output->require; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | Rex::Output->get( $opts{'o'} ); | |||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | handle_lock_file($::rexfile); | |||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | Rex::Config->set_environment( $opts{"E"} ) if ( $opts{"E"} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | if ( $opts{'g'} || $opts{'G'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opts{"g"} or $opts{"G"}
MC/DC0%0/2
$opts{"g"} or $opts{"G"}
$opts{"g"}
$opts{"G"}
Truth table0%0/3
A or B
A= $opts{"g"}B= $opts{"G"}
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | #$::FORCE_SERVER = "\0" . $opts{'g'}; | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | $opts{'g'} ||= $opts{'G'}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$opts{"g"} ||= $opts{"G"}
MC/DC0%0/2
$opts{"g"} ||= $opts{"G"}
$opts{"g"}
$opts{"G"}
Truth table0%0/3
A ||= B
A= $opts{"g"}B= $opts{"G"}
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | if ( ref $opts{'g'} ne "ARRAY" ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | $::FORCE_SERVER = [ $opts{'g'} ]; | |||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||
| 187 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | $::FORCE_SERVER = $opts{'g'}; | |||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | load_server_ini_file($::rexfile); | |||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | load_rexfile($::rexfile); | |||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | #### check if some parameters should be overwritten from the command line | ||||||||||||||||||||||||||||||||||||||||||
| 196 | CHECK_OVERWRITE: { | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | my $pass_auth = 0; | |||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | if ( $opts{'u'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | Rex::Commands::user( $opts{'u'} ); | |||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | for my $task ( Rex::TaskList->create()->get_tasks ) { | |||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | Rex::TaskList->create()->get_task($task)->set_user( $opts{'u'} ); | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | if ( $opts{'p'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | Rex::Commands::password( $opts{'p'} ); | |||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | unless ( $opts{'P'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | $pass_auth = 1; | |||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | for my $task ( Rex::TaskList->create()->get_tasks ) { | |||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | Rex::TaskList->create()->get_task($task)->set_password( $opts{'p'} ); | |||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | if ( $opts{'P'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | Rex::Commands::private_key( $opts{'P'} ); | |||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | for my $task ( Rex::TaskList->create()->get_tasks ) { | |||||||||||||||||||||||||||||||||||||||||
| 224 | Rex::TaskList->create() | ||||||||||||||||||||||||||||||||||||||||||
| 225 | ->get_task($task) | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ->set_auth( "private_key", $opts{'P'} ); | |||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | if ( $opts{'K'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | Rex::Commands::public_key( $opts{'K'} ); | |||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | for my $task ( Rex::TaskList->create()->get_tasks ) { | |||||||||||||||||||||||||||||||||||||||||
| 234 | Rex::TaskList->create() | ||||||||||||||||||||||||||||||||||||||||||
| 235 | ->get_task($task) | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ->set_auth( "public_key", $opts{'K'} ); | |||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | if ($pass_auth) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | pass_auth; | |||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | Rex::Logger::debug("Initializing Logger from parameters found in $::rexfile"); | |||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | if ( $opts{'T'} && $opts{'m'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
$opts{"T"} and $opts{"m"}
MC/DC0%0/2
$opts{"T"} and $opts{"m"}
$opts{"T"}
$opts{"m"}
Truth table0%0/3
A and B
A= $opts{"T"}B= $opts{"m"}
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | # create machine readable tasklist | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | my @tasks = Rex::TaskList->create()->get_tasks; | |||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | for my $task (@tasks) { | |||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | my $desc = Rex::TaskList->create()->get_desc($task); | |||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | $desc =~ s/'/\\'/gms; | |||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | print "'$task'" . " = '$desc'\n"; | |||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 258 | ▶ | elsif ( $opts{'T'} && $opts{'y'} ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$opts{"T"} and $opts{"y"}
MC/DC0%0/2
$opts{"T"} and $opts{"y"}
$opts{"T"}
$opts{"y"}
Truth table0%0/3
A and B
A= $opts{"T"}B= $opts{"y"}
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | my @tasks = Rex::TaskList->create()->get_tasks; | |||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | my @envs = Rex::Commands->get_environments(); | |||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | my %groups = Rex::Group->get_groups; | |||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | my %real_groups; | |||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | for my $group ( keys %groups ) { | |||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | my @servers = map { $_->get_servers } | |||||||||||||||||||||||||||||||||||||||||
| 267 | Rex::Group->get_group_object($group)->get_servers; | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | $real_groups{$group} = \@servers; | |||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | print YAML::Dump( | |||||||||||||||||||||||||||||||||||||||||
| 272 | { | ||||||||||||||||||||||||||||||||||||||||||
| 273 | tasks => \@tasks, | ||||||||||||||||||||||||||||||||||||||||||
| 274 | envs => \@envs, | ||||||||||||||||||||||||||||||||||||||||||
| 275 | groups => \%real_groups, | ||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||
| 279 | elsif ( $opts{'T'} ) { | ||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | _handle_T(%opts); | |||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | Rex::global_sudo(0); | |||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | Rex::Logger::debug("Removing lockfile") if ( !exists $opts{'F'} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | CORE::unlink("$::rexfile.lock") if ( !exists $opts{'F'} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | CORE::exit 0; | |||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | # turn sudo on with cli option s is used | ||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | if ( exists $opts{'s'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | sudo("on"); | |||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | if ( exists $opts{'S'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | sudo_password( $opts{'S'} ); | |||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | if ( exists $opts{'t'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | parallelism( $opts{'t'} ); | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | if ( $opts{'e'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | Rex::Logger::debug("Executing command line code"); | |||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | Rex::Logger::debug( "\t" . $opts{'e'} ); | |||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | # execute the given code | ||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | my $code = "sub { \n"; | |||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | $code .= $opts{'e'} . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | $code .= "}"; | |||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | $code = eval($code); | |||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | if ($EVAL_ERROR) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | Rex::Logger::info( "Error in eval line: $EVAL_ERROR\n", "warn" ); | |||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | exit 1; | |||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | if ( exists $opts{'t'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | parallelism( $opts{'t'} ); | |||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | my $pass_auth = 0; | |||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | if ( $opts{'u'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | Rex::Commands::user( $opts{'u'} ); | |||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | if ( $opts{'p'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | Rex::Commands::password( $opts{'p'} ); | |||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | unless ( $opts{'P'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | $pass_auth = 1; | |||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | if ( $opts{'P'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | Rex::Commands::private_key( $opts{'P'} ); | |||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | if ( $opts{'K'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | Rex::Commands::public_key( $opts{'K'} ); | |||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | if ($pass_auth) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | pass_auth; | |||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | my @params = (); | |||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | if ( $opts{'H'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | push @params, split( /\s+/, $opts{'H'} ); | |||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | push @params, $code; | |||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | push @params, "eval-line-desc"; | |||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | push @params, {}; | |||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | Rex::TaskList->create()->create_task( "eval-line", @params ); | |||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | Rex::Commands::do_task("eval-line"); | |||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | exit_rex(); | |||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 358 | elsif ( $opts{'M'} ) { | ||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | Rex::Logger::debug( "Loading Rex-Module: " . $opts{'M'} ); | |||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | my $mod = $opts{'M'}; | |||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | $mod =~ s{::}{/}g; | |||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | $mod .= ".pm"; | |||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | require $mod; | |||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | my $run_list = Rex::RunList->instance; | |||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | if ( $opts{'b'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | my $batch = $opts{'b'}; | |||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | Rex::Logger::debug("Running batch: $batch"); | |||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | $run_list->add_task($_) for Rex::Batch->get_batch($batch); | |||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | $run_list->parse_opts(@ARGV); | |||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | eval { $run_list->run_tasks }; | |||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | if ($EVAL_ERROR) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | # this is always the child | ||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | Rex::Logger::info( "Error running task/batch: $EVAL_ERROR", "warn" ); | |||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | CORE::exit(0); | |||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | exit_rex(); | |||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | sub _print_color { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_print_color: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | my ( $msg, $color ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | $color = 'green' if !defined($color); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | if ($no_color) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | print $msg; | |||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||
| 394 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | print colored( [$color], $msg ); | |||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | sub __help__ { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__help__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | my $fmt = " %-6s %s\n"; | |||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | print "usage: \n"; | |||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | print " rex [<options>] [-H <host>] [-G <group>] <task> [<task-options>]\n"; | |||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | print " rex -T[m|y|v] [<string>]\n"; | |||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | printf $fmt, "-b", "Run batch"; | |||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | printf $fmt, "-e", "Run the given code fragment"; | |||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | printf $fmt, "-E", "Execute a task on the given environment"; | |||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | printf $fmt, "-G|-g", "Execute a task on the given server groups"; | |||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | printf $fmt, "-H", "Execute a task on the given hosts (space delimited)"; | |||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | printf $fmt, "-z", "Execute a task on hosts from this command's output"; | |||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | printf $fmt, "-K", "Public key file for the ssh connection"; | |||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | printf $fmt, "-P", "Private key file for the ssh connection"; | |||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | printf $fmt, "-p", "Password for the ssh connection"; | |||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | printf $fmt, "-u", "Username for the ssh connection"; | |||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | printf $fmt, "-d", "Show debug output"; | |||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | printf $fmt, "-ddd", "Show more debug output (includes profiling output)"; | |||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | printf $fmt, "-m", "Monochrome output: no colors"; | |||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | printf $fmt, "-o", "Output format"; | |||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | printf $fmt, "-q", "Quiet mode: no log output"; | |||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | printf $fmt, "-qw", "Quiet mode: only output warnings and errors"; | |||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | printf $fmt, "-Q", "Really quiet: output nothing"; | |||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | printf $fmt, "-T", "List tasks"; | |||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | printf $fmt, "-Ta", "List all tasks, including hidden"; | |||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | printf $fmt, "-Tm", "List tasks in machine-readable format"; | |||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | printf $fmt, "-Tv", "List tasks verbosely"; | |||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | printf $fmt, "-Ty", "List tasks in YAML format"; | |||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | printf $fmt, "-c", "Turn cache ON"; | |||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | printf $fmt, "-C", "Turn cache OFF"; | |||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | printf $fmt, "-f", "Use this file instead of Rexfile"; | |||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | printf $fmt, "-F", "Force: disregard lock file"; | |||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | printf $fmt, "-h", "Display this help message"; | |||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | printf $fmt, "-M", "Load this module instead of Rexfile"; | |||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | printf $fmt, "-O", "Pass additional options, like CMDB path"; | |||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | printf $fmt, "-s", "Use sudo for every command"; | |||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | printf $fmt, "-S", "Password for sudo"; | |||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | printf $fmt, "-t", "Number of threads to use (aka 'parallelism' param)"; | |||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | printf $fmt, "-v", "Display (R)?ex version"; | |||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | for my $code (@help) { | |||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | &$code(); | |||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | CORE::exit 0; | |||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | ▶ | sub add_help { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_help: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | my ( $self, $code ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | push( @help, $code ); | |||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||
| 459 | 1 | ▶ | sub add_exit { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_exit: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 460 | 1 | my ( $self, $code ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 461 | 1 | push( @exit, $code ); | |||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | ▶ | sub __version__ { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__version__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | print "(R)?ex " . $Rex::VERSION . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | CORE::exit 0; | |||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | ▶ | sub _handle_T { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_handle_T: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | my %opts = @_; | |||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | my ($cols) = Term::ReadKey::GetTerminalSize(*STDOUT); | |||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | ▶ | $Text::Wrap::columns = $cols || 80; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$cols || 80
MC/DC0%0/1
$cols || 80
$cols
Truth table0%0/2
A
A= $cols
| |||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | _list_tasks(); | |||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | _list_batches(); | |||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | _list_envs(); | |||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | _list_groups(); | |||||||||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | ▶ | sub _list_tasks { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_list_tasks: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | Rex::Logger::debug("Listing Tasks"); | |||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | my @tasks; | |||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | ▶ | if ( $opts{'a'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | @tasks = sort Rex::TaskList->create()->get_all_tasks(qr/.*/); | |||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||
| 488 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | @tasks = Rex::TaskList->create()->get_tasks; | |||||||||||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | ▶ | if ( defined $ARGV[0] ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | @tasks = grep { $_ =~ /^$ARGV[0]/ } @tasks; | |||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||
| 495 | # Warn if the user passed args to '-T' and no matching task names were found | ||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | ▶ | Rex::Logger::info( "No tasks matching '$ARGV[0]' found.", "error" ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 497 | unless @tasks; | ||||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | ▶ | return unless @tasks; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | # fancy sorting of tasks -- put tasks from Rexfile first | ||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | my @root_tasks = grep { !/:/ } @tasks; | |||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | my @other_tasks = grep { /:/ } @tasks; | |||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | @tasks = ( sort(@root_tasks), sort(@other_tasks) ); | |||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | _print_color( "Tasks\n", "yellow" ); | |||||||||||||||||||||||||||||||||||||||||
| 508 | 0 | my $max_task_len = max map { length } @tasks; | |||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | my $fmt = " %-" . $max_task_len . "s %s\n"; | |||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | my $last_namespace = _namespace( $tasks[0] ); | |||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | for my $task (@tasks) { | |||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | ▶ | print "\n" if $last_namespace ne _namespace($task); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | $last_namespace = _namespace($task); | |||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | my $description = Rex::TaskList->create()->get_desc($task); | |||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | my $output = sprintf $fmt, $task, $description; | |||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | my $indent = " " x $max_task_len . " "; | |||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | print wrap( "", $indent, $output ); | |||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | ▶ | if ( $opts{'v'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | my @servers = sort @{ Rex::TaskList->create()->get_task($task)->server }; | |||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | _print_color( " Servers: " . join( ", ", @servers ) . "\n" ); | |||||||||||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | ▶ | sub _namespace { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_namespace: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | my ($full_task_name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | ▶ | return "" unless $full_task_name =~ /:/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | my ($namespace) = split /:/, $full_task_name; | |||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | return $namespace; | |||||||||||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | ▶ | sub _list_batches { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_list_batches: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | Rex::Logger::debug("Listing Batches"); | |||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | my @batchs = sort Rex::Batch->get_batchs; | |||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | ▶ | return unless Rex::Batch->get_batchs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | _print_color( "Batches\n", 'yellow' ); | |||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | my $max_batch_len = max map { length } @batchs; | |||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | my $fmt = " %-" . $max_batch_len . "s %s\n"; | |||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | for my $batch ( sort @batchs ) { | |||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | my $description = Rex::Batch->get_desc($batch); | |||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | my $output = sprintf $fmt, $batch, $description; | |||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | my $indent = " " x $max_batch_len . " "; | |||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | print wrap( "", $indent, $output ); | |||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | ▶ | if ( $opts{'v'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | my @tasks = Rex::Batch->get_batch($batch); | |||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | _print_color( " " . join( " ", @tasks ) . "\n" ); | |||||||||||||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | ▶ | sub _list_envs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_list_envs: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | Rex::Logger::debug("Listing Envs"); | |||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||
| 563 | my @envs = | ||||||||||||||||||||||||||||||||||||||||||
| 564 | 0 | map { Rex::Commands->get_environment($_) } | |||||||||||||||||||||||||||||||||||||||||
| 565 | sort Rex::Commands->get_environments(); | ||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | ▶ | return unless @envs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | ▶ | _print_color( "Environments\n", "yellow" ) if scalar @envs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | my $max_env_len = max map { length $_->{name} } @envs; | |||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | my $fmt = " %-" . $max_env_len . "s %s\n"; | |||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | for my $e ( sort @envs ) { | |||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | my $output = sprintf $fmt, $e->{name}, $e->{description}; | |||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | my $indent = " " x $max_env_len . " "; | |||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | print wrap( "", $indent, $output ); | |||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | ▶ | sub _list_groups { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_list_groups: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | Rex::Logger::debug("Listing Groups"); | |||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | my %groups = Rex::Group->get_groups; | |||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | my @group_names = sort keys %groups; | |||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | ▶ | return unless @group_names; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | _print_color( "Server Groups\n", "yellow" ); | |||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | my $max_group_len = max map { length } @group_names; | |||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | my $fmt = " %-" . $max_group_len . "s %s\n"; | |||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | for my $group_name (@group_names) { | |||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | my $hosts = join( ", ", sort @{ $groups{$group_name} } ); | |||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | my $output = sprintf $fmt, $group_name, $hosts; | |||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | my $indent = " " x $max_group_len . " "; | |||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | print wrap( "", $indent, $output ); | |||||||||||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | ▶ | sub summarize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
summarize: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | my ($signal) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | my %opts = Rex::Args->getopts; | |||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | ▶ | return if $opts{'T'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | my @summary = Rex::TaskList->create()->get_summary(); | |||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | ▶ | return unless @summary; # no tasks ran -- nothing to summarize | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | my @failures = grep { $_->{exit_code} != 0 } @summary; | |||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | ▶ | if ( !@failures ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | Rex::Logger::info("All tasks successful on all hosts"); | |||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||
| 614 | 0 | Rex::Logger::info( @failures . " out of " . @summary . " task(s) failed:", | |||||||||||||||||||||||||||||||||||||||||
| 615 | "error" ); | ||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||
| 617 | 0 | foreach ( | |||||||||||||||||||||||||||||||||||||||||
| 618 | sort { | ||||||||||||||||||||||||||||||||||||||||||
| 619 | ncmp( $a->{task}, $b->{task} ) | ||||||||||||||||||||||||||||||||||||||||||
| 620 | || ncmp( $a->{server}, $b->{server} ) | ||||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | ▶ | } @failures | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ncmp($Rex::CLI::a->{'task'}, $Rex::CLI::b->{'task'}) || ncmp($Rex::CLI::a->{'server'}, $Rex::CLI::b->{'server'})
MC/DC0%0/2
ncmp($Rex::CLI::a->{'task'}, $Rex::CLI::b->{'task'}) || ncmp($Rex::CLI::a->{'server'}, $Rex::CLI::b->{'server'})
ncmp($Rex::CLI::a->{'task'}, $Rex::CLI::b->{'task'})
ncmp($Rex::CLI::a->{'server'}, $Rex::CLI::b->{'server'})
Truth table0%0/3
A || B
A= ncmp($Rex::CLI::a->{'task'}, $Rex::CLI::b->{'task'})B= ncmp($Rex::CLI::a->{'server'}, $Rex::CLI::b->{'server'})
| |||||||||||||||||||||||||||||||||||||||||||
| 622 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 623 | { | ||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | Rex::Logger::info( "\t$_->{task} failed on $_->{server}", "error" ); | |||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | ▶ | if ( $_->{error_message} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | for my $line ( split( $INPUT_RECORD_SEPARATOR, $_->{error_message} ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 627 | 0 | Rex::Logger::info( "\t\t$line", "error" ); | |||||||||||||||||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||||||||||||||||
| 630 | } | ||||||||||||||||||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||
| 633 | 0 | ▶ | sub handle_lock_file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_lock_file: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | my $rexfile = shift; | |||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | ▶ | if ( $OSNAME !~ m/^MSWin/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | ▶ | if ( -f "$rexfile.lock" && !exists $opts{'F'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f "$rexfile.lock" and not exists $opts{"F"}
MC/DC0%0/2
-f "$rexfile.lock" and not exists $opts{"F"}
-f "$rexfile.lock"
not exists $opts{"F"}
Truth table0%0/3
A and not(B)
A= -f "$rexfile.lock"B= not exists $opts{"F"}
| |||||||||||||||||||||||||||||||||||||||||||
| 638 | 0 | Rex::Logger::debug("Found $rexfile.lock"); | |||||||||||||||||||||||||||||||||||||||||
| 639 | 0 | my $pid = eval { | |||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | local ( @ARGV, $INPUT_RECORD_SEPARATOR ) = ("$rexfile.lock"); | |||||||||||||||||||||||||||||||||||||||||
| 641 | 0 | <>; | |||||||||||||||||||||||||||||||||||||||||
| 642 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 643 | 0 | system( | |||||||||||||||||||||||||||||||||||||||||
| 644 | "ps aux | awk -F' ' ' { print \$2 } ' | grep $pid >/dev/null 2>&1"); | ||||||||||||||||||||||||||||||||||||||||||
| 645 | 0 | ▶ | if ( $CHILD_ERROR == 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | Rex::Logger::info("Rexfile is in use by $pid."); | |||||||||||||||||||||||||||||||||||||||||
| 647 | 0 | CORE::exit 1; | |||||||||||||||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||||||||||||||||
| 649 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | Rex::Logger::debug("Found stale lock file. Removing it."); | |||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | Rex::global_sudo(0); | |||||||||||||||||||||||||||||||||||||||||
| 652 | 0 | CORE::unlink("$rexfile.lock"); | |||||||||||||||||||||||||||||||||||||||||
| 653 | } | ||||||||||||||||||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||
| 656 | 0 | Rex::Logger::debug("Creating lock-file ($rexfile.lock)"); | |||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | ▶ | open( my $f, ">", "$rexfile.lock" ) or die($OS_ERROR); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | print $f $PID; | |||||||||||||||||||||||||||||||||||||||||
| 659 | 0 | close($f); | |||||||||||||||||||||||||||||||||||||||||
| 660 | } | ||||||||||||||||||||||||||||||||||||||||||
| 661 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 662 | 0 | Rex::Logger::debug("Running on windows. Disabled lock file support."); | |||||||||||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||||||||||
| 664 | } | ||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | ▶ | sub load_server_ini_file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_server_ini_file: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | my $rexfile = shift; | |||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||
| 669 | # load server ini file | ||||||||||||||||||||||||||||||||||||||||||
| 670 | 0 | my $env = environment; | |||||||||||||||||||||||||||||||||||||||||
| 671 | 0 | my $ini_dir = dirname($rexfile); | |||||||||||||||||||||||||||||||||||||||||
| 672 | 0 | my $server_ini_file = "$ini_dir/server.$env.ini"; | |||||||||||||||||||||||||||||||||||||||||
| 673 | 0 | ▶ | $server_ini_file = "$ini_dir/server.ini" unless -f $server_ini_file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||||||||||||
| 675 | 0 | ▶ | if ( -f $server_ini_file && Rex::Group::Lookup::INI->is_loadable ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f $server_ini_file and "Rex::Group::Lookup::INI"->is_loadable
MC/DC0%0/2
-f $server_ini_file and "Rex::Group::Lookup::INI"->is_loadable
-f $server_ini_file
"Rex::Group::Lookup::INI"->is_loadable
Truth table0%0/3
A and B
A= -f $server_ini_fileB= "Rex::Group::Lookup::INI"->is_loadable
| |||||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | Rex::Logger::debug("Loading $server_ini_file"); | |||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | Rex::Group::Lookup::INI::groups_file($server_ini_file); | |||||||||||||||||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||
| 681 | 9 | ▶ | sub load_rexfile { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_rexfile: called CC=10 SCAR=23.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 682 | 9 | my $rexfile = shift; | |||||||||||||||||||||||||||||||||||||||||
| 683 | 9 | Rex::Logger::debug("Loading $rexfile"); | |||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||
| 685 | 9 | ▶ | if ( !-f $rexfile ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 686 | 1 | ▶ | if ( !exists $opts{'e'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 687 | 1 | Rex::Logger::info( "No Rexfile found.", "warn" ); | |||||||||||||||||||||||||||||||||||||||||
| 688 | 1 | Rex::Logger::info( "Create a file named 'Rexfile' in this directory,", | |||||||||||||||||||||||||||||||||||||||||
| 689 | "warn" ); | ||||||||||||||||||||||||||||||||||||||||||
| 690 | 1 | Rex::Logger::info( "or specify the file you want to use with:", "warn" ); | |||||||||||||||||||||||||||||||||||||||||
| 691 | 1 | Rex::Logger::info( " rex -f file_to_use task_to_run", "warn" ); | |||||||||||||||||||||||||||||||||||||||||
| 692 | } | ||||||||||||||||||||||||||||||||||||||||||
| 693 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 694 | } | ||||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||
| 696 | 8 | my $rexfile_dir = dirname $rexfile; | |||||||||||||||||||||||||||||||||||||||||
| 697 | 8 | my @new_inc = Rex::generate_inc($rexfile_dir); | |||||||||||||||||||||||||||||||||||||||||
| 698 | 8 | @INC = @new_inc; | |||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||
| 700 | # load Rexfile | ||||||||||||||||||||||||||||||||||||||||||
| 701 | 8 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||||||||||||
| 703 | # add a true return value at the end of $rexfile. | ||||||||||||||||||||||||||||||||||||||||||
| 704 | # we need to do this because perl want a "true" value | ||||||||||||||||||||||||||||||||||||||||||
| 705 | # at the end of a file that is loaded. | ||||||||||||||||||||||||||||||||||||||||||
| 706 | 20 | ▶ | unshift @INC, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.6
| |||||||||||||||||||||||||||||||||||||||||||
| 707 | 20 | my $load_file = $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 708 | 20 | ▶ | if ( $load_file eq "__Rexfile__.pm" ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 709 | 7 | ▶ | open( my $fh, "<", $rexfile ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 710 | or die("Error can't open $rexfile: $OS_ERROR"); | ||||||||||||||||||||||||||||||||||||||||||
| 711 | 7 | my @content = <$fh>; | |||||||||||||||||||||||||||||||||||||||||
| 712 | 7 | close($fh); | |||||||||||||||||||||||||||||||||||||||||
| 713 | 7 | chomp @content; | |||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||
| 715 | 7 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 716 | 7 | my $found_end = 0; | |||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||
| 718 | # some rexfile has a __DATA__ or __END__ section | ||||||||||||||||||||||||||||||||||||||||||
| 719 | # and we need to add the true value before those sections. | ||||||||||||||||||||||||||||||||||||||||||
| 720 | 7 | for my $line (@content) { | |||||||||||||||||||||||||||||||||||||||||
| 721 | 47 | ▶ | if ( $line =~ m/^__(DATA|END)__$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | splice( @content, $i, 0, "42;" ); | |||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | $found_end++; | |||||||||||||||||||||||||||||||||||||||||
| 724 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||||
| 726 | 47 | $i++; | |||||||||||||||||||||||||||||||||||||||||
| 727 | } | ||||||||||||||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||||||||||||||
| 729 | # we didn't found __DATA__ or __END__ so we just add | ||||||||||||||||||||||||||||||||||||||||||
| 730 | # it at the end. | ||||||||||||||||||||||||||||||||||||||||||
| 731 | 7 | ▶ | if ( $found_end == 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 732 | 7 | push @content, "42;"; | |||||||||||||||||||||||||||||||||||||||||
| 733 | } | ||||||||||||||||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||||||||||||||||
| 735 | # we can't remove this load from @INC because on perl 5.8 | ||||||||||||||||||||||||||||||||||||||||||
| 736 | # this causes a crash | ||||||||||||||||||||||||||||||||||||||||||
| 737 | #shift @INC; # remove this loader from @INC | ||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||
| 739 | # we can't directly return a scalar reference because perl 5.8 | ||||||||||||||||||||||||||||||||||||||||||
| 740 | # needs a filehandle. so we create a virtual filehandle... | ||||||||||||||||||||||||||||||||||||||||||
| 741 | 7 | my $c = join( "\n", @content ); | |||||||||||||||||||||||||||||||||||||||||
| 742 | 7 | open( my $rex_fh, "<", \$c ); | |||||||||||||||||||||||||||||||||||||||||
| 743 | 7 | return $rex_fh; | |||||||||||||||||||||||||||||||||||||||||
| 744 | } | ||||||||||||||||||||||||||||||||||||||||||
| 745 | 8 | }; | |||||||||||||||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||||||||||||||||
| 747 | # we don't want to see the | ||||||||||||||||||||||||||||||||||||||||||
| 748 | # normal perl warning message on the screen. Instead we print | ||||||||||||||||||||||||||||||||||||||||||
| 749 | # the warning message in the catch-if below | ||||||||||||||||||||||||||||||||||||||||||
| 750 | 8 | my @warnings; | |||||||||||||||||||||||||||||||||||||||||
| 751 | 8 | ▶ | local $SIG{__WARN__} = sub { push @warnings, $_[0] }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||||||||||||||||
| 753 | # we can't use $rexfile here, because if the variable contains dots | ||||||||||||||||||||||||||||||||||||||||||
| 754 | # the perl interpreter try to load the file directly without using @INC | ||||||||||||||||||||||||||||||||||||||||||
| 755 | # so we just fake a module name. | ||||||||||||||||||||||||||||||||||||||||||
| 756 | 8 | require __Rexfile__; | |||||||||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||||||||
| 758 | # update %INC so that we can later use it to find the rexfile | ||||||||||||||||||||||||||||||||||||||||||
| 759 | 6 | $INC{"__Rexfile__.pm"} = $rexfile; | |||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||
| 761 | 6 | ▶ | if (@warnings) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 762 | 2 | Rex::Logger::info( "You have some code warnings:", 'warn' ); | |||||||||||||||||||||||||||||||||||||||||
| 763 | 2 | for (@warnings) { | |||||||||||||||||||||||||||||||||||||||||
| 764 | 4 | chomp; | |||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||
| 766 | 4 | my $message = _tidy_loading_message( $_, $rexfile ); | |||||||||||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||||||||||||
| 768 | 4 | Rex::Logger::info( "\t$message", 'warn' ); | |||||||||||||||||||||||||||||||||||||||||
| 769 | } | ||||||||||||||||||||||||||||||||||||||||||
| 770 | } | ||||||||||||||||||||||||||||||||||||||||||
| 771 | |||||||||||||||||||||||||||||||||||||||||||
| 772 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 773 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||||||||||||
| 775 | 8 | ▶ | if ($EVAL_ERROR) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 776 | 2 | my $e = $EVAL_ERROR; | |||||||||||||||||||||||||||||||||||||||||
| 777 | 2 | chomp $e; | |||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||
| 779 | 2 | $e = _tidy_loading_message( $e, $rexfile ); | |||||||||||||||||||||||||||||||||||||||||
| 780 | |||||||||||||||||||||||||||||||||||||||||||
| 781 | 2 | my ( @error_lines, @debug_lines ); | |||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||
| 783 | 2 | for my $line ( split $INPUT_RECORD_SEPARATOR, $e ) { | |||||||||||||||||||||||||||||||||||||||||
| 784 | 10 | ▶ | $line =~ m{CLI[.]pm[ ]line[ ]\d+}msx | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 785 | ? push @debug_lines, $line | ||||||||||||||||||||||||||||||||||||||||||
| 786 | : push @error_lines, $line; | ||||||||||||||||||||||||||||||||||||||||||
| 787 | } | ||||||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||||||
| 789 | 2 | Rex::Logger::info( "Compile time errors:", 'error' ); | |||||||||||||||||||||||||||||||||||||||||
| 790 | |||||||||||||||||||||||||||||||||||||||||||
| 791 | 2 | for my $error_line (@error_lines) { | |||||||||||||||||||||||||||||||||||||||||
| 792 | 8 | Rex::Logger::info( "\t$error_line", 'error' ); | |||||||||||||||||||||||||||||||||||||||||
| 793 | } | ||||||||||||||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||||||||||||
| 795 | 2 | for my $debug_line (@debug_lines) { | |||||||||||||||||||||||||||||||||||||||||
| 796 | 2 | Rex::Logger::debug("\t$debug_line"); | |||||||||||||||||||||||||||||||||||||||||
| 797 | } | ||||||||||||||||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||||||||||||||||
| 799 | 2 | exit 1; | |||||||||||||||||||||||||||||||||||||||||
| 800 | } | ||||||||||||||||||||||||||||||||||||||||||
| 801 | } | ||||||||||||||||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||||||||||||||||
| 803 | 6 | ▶ | sub _tidy_loading_message { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tidy_loading_message: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 804 | 6 | my ( $message, $rexfile ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||||||||||||
| 806 | 6 | $message =~ s{/loader/[^/]+/__Rexfile__[.]pm}{$rexfile}gmsx; | |||||||||||||||||||||||||||||||||||||||||
| 807 | 6 | return $message; | |||||||||||||||||||||||||||||||||||||||||
| 808 | } | ||||||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||||||
| 810 | 0 | ▶ | sub exit_rex { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exit_rex: not called CC=13 SCAR=52.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 811 | 0 | my ( $exit_code_override, $signal ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||||||||||||||||
| 813 | 0 | ▶ | summarize($signal) if !$signal; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||||||||||||
| 815 | 0 | Rex::global_sudo(0); | |||||||||||||||||||||||||||||||||||||||||
| 816 | 0 | ▶ | Rex::Logger::debug("Removing lockfile") if !exists $opts{'F'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 817 | 0 | ▶ | unlink("$::rexfile.lock") if !exists $opts{'F'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||||||||||||||||
| 819 | 0 | select STDOUT; | |||||||||||||||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||||||||||||||||
| 821 | 0 | ▶ | if ( !$signal && $opts{'o'} && defined( Rex::Output->get ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not $signal and $opts{"o"} and defined "Rex::Output"->get
not $signal and $opts{"o"}
MC/DC0%0/3
not $signal and $opts{"o"} and defined "Rex::Output"->get
not $signal
$opts{"o"}
defined "Rex::Output"->get
Truth table0%0/4
not(A) and B and C
A= not $signalB= $opts{"o"}C= defined "Rex::Output"->get
| |||||||||||||||||||||||||||||||||||||||||||
| 822 | 0 | Rex::Output->get->write(); | |||||||||||||||||||||||||||||||||||||||||
| 823 | 0 | IPC::Shareable->clean_up_all(); | |||||||||||||||||||||||||||||||||||||||||
| 824 | } | ||||||||||||||||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||||||||||||||||
| 826 | 0 | for my $exit_hook (@exit) { | |||||||||||||||||||||||||||||||||||||||||
| 827 | 0 | $exit_hook->( $exit_code_override, $signal ); | |||||||||||||||||||||||||||||||||||||||||
| 828 | } | ||||||||||||||||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||||||||||||||||
| 830 | 0 | ▶ | if ($Rex::WITH_EXIT_STATUS) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 831 | 0 | ▶ | CORE::exit($exit_code_override) if defined $exit_code_override; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||||||||||||||||
| 833 | 0 | my @exit_codes = Rex::TaskList->create()->get_exit_codes(); | |||||||||||||||||||||||||||||||||||||||||
| 834 | 0 | for my $exit_code (@exit_codes) { | |||||||||||||||||||||||||||||||||||||||||
| 835 | 0 | ▶ | $exit_code = $exit_code >> 8 if $exit_code > 255; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 836 | 0 | ▶ | CORE::exit($exit_code) if $exit_code != 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 837 | } | ||||||||||||||||||||||||||||||||||||||||||
| 838 | } | ||||||||||||||||||||||||||||||||||||||||||
| 839 | |||||||||||||||||||||||||||||||||||||||||||
| 840 | 0 | CORE::exit(0); | |||||||||||||||||||||||||||||||||||||||||
| 841 | } | ||||||||||||||||||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||||||||||||||||
| 843 | # we capture CTRL+C so we can cleanup vars files | ||||||||||||||||||||||||||||||||||||||||||
| 844 | # and give modules the chance to also do cleanup | ||||||||||||||||||||||||||||||||||||||||||
| 845 | 0 | ▶ | $SIG{INT} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 846 | 0 | exit_rex( 1, "INT" ); | |||||||||||||||||||||||||||||||||||||||||
| 847 | 15 | }; | |||||||||||||||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||||||||||||||||
| 849 | 15 | 1; | |||||||||||||||||||||||||||||||||||||||||