| 1 | #!/usr/local/bin/perl | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Getopt::Long; Getopt::Long::Configure("bundling"); # make switches case sensitive (and turn on bundling) | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Pod::Usage; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use App::MrShell; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 1 | my @hosts; | |||||||||||||||||||||||||||||||
| 11 | 1 | my $conf = "$ENV{HOME}/.mrshrc"; | |||||||||||||||||||||||||||||||
| 12 | 1 | my $log; | |||||||||||||||||||||||||||||||
| 13 | my $shell; | ||||||||||||||||||||||||||||||||
| 14 | 1 | my $trunc; | |||||||||||||||||||||||||||||||
| 15 | 1 | my $debug; | |||||||||||||||||||||||||||||||
| 16 | 1 | my $no_esc; | |||||||||||||||||||||||||||||||
| 17 | 1 | my $show_groups_and_exit; | |||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | 1 | my @orig_ARGV = @ARGV; | |||||||||||||||||||||||||||||||
| 20 | MAGICALLY_UNDERSTAND_HOSTGROUPS: { | ||||||||||||||||||||||||||||||||
| 21 | 1 | GetOptions( | |||||||||||||||||||||||||||||||
| 22 | "groups|list|g" => \$show_groups_and_exit, | ||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | "version|v" => sub { print "This is Mr. Shell version $App::MrShell::VERSION.\n\n"; pod2usage() }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 24 | "host|H=s@" => \@hosts, | ||||||||||||||||||||||||||||||||
| 25 | "conf|c:s" => \$conf, # optional value | ||||||||||||||||||||||||||||||||
| 26 | "noesc|N" => \$no_esc, | ||||||||||||||||||||||||||||||||
| 27 | "log|l=s" => \$log, | ||||||||||||||||||||||||||||||||
| 28 | "trunc|t" => \$trunc, # whether to truncate the log file | ||||||||||||||||||||||||||||||||
| 29 | 'debug|d:i' => \$debug, | ||||||||||||||||||||||||||||||||
| 30 | "shell|s=s" => \$shell, | ||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | "help|h" => sub { pod2usage(-verbose=>1) }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | ) or pod2usage(); do{ warn "ERROR: command required\n"; pod2usage()} unless @ARGV or $show_groups_and_exit; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
@ARGV or $show_groups_and_exit
MC/DC0%0/2
@ARGV or $show_groups_and_exit
@ARGV
$show_groups_and_exit
Truth table33%1/3
A or B
A= @ARGVB= $show_groups_and_exit
| |||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | no warnings 'uninitialized'; ## no critic: this is a stupid warning anyway | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 36 | 1 | ▶ | if( $ARGV[0] =~ m/^\@/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | while( $ARGV[0] =~ m/^\@/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | @orig_ARGV = map { $_ eq $ARGV[0] ? ('-H'=>$_) : ($_) } @orig_ARGV; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 39 | 0 | shift @ARGV; | |||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | 0 | @ARGV = @orig_ARGV; ## no critic: no I really really meant to change the global one, thanks | |||||||||||||||||||||||||||||||
| 43 | 0 | redo MAGICALLY_UNDERSTAND_HOSTGROUPS; | |||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | 1 | my $mrsh = App::MrShell->new->set_usage_error("pod2usage"); | |||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | $mrsh->read_config($conf) if $conf; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 50 | 1 | ▶ | show_groups_and_exit() if $show_groups_and_exit; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | $mrsh->set_logfile_option($log, $trunc) if $log; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 52 | 1 | ▶ | $mrsh->set_shell_command_option($shell) if $shell; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 53 | 1 | ▶ | $mrsh->set_debug_option($debug) if defined $debug; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | $mrsh->set_no_command_escapes_option if $no_esc; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 1 | $mrsh->set_hosts(@hosts) # tell Mr. Shell where to run things | |||||||||||||||||||||||||||||||
| 57 | ->queue_command(@ARGV) # queue a command for whatever hosts are set | ||||||||||||||||||||||||||||||||
| 58 | ->run_queue; # tell POE to do what POE does | ||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub show_groups_and_exit { | ||||||||||||||||||||||||||||||
|
Subroutine
show_groups_and_exit: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||
| 61 | 0 | my %groups = $mrsh->groups; | |||||||||||||||||||||||||||||||
| 62 | 0 | my @groups = sort keys %groups; | |||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if( my @h = grep {s/^@//} @hosts ) { ## no critic: bah | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 65 | 0 | @groups = @h; | |||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | unless(@groups) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 69 | 0 | print "(no gropus to show)\n"; | |||||||||||||||||||||||||||||||
| 70 | 0 | exit 0; | |||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | 0 | my $len = length $groups[0]; | |||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | for(@groups) { $len = length $_ if length $_ > $len } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | 0 | $len ++; | |||||||||||||||||||||||||||||||
| 77 | 0 | for(@groups) { | |||||||||||||||||||||||||||||||
| 78 | 0 | printf '%-*s %s', $len, "$_:", "@{ $groups{$_} }\n"; | |||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | 0 | exit 0; | |||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | __END__ | ||||||||||||||||||||||||||||||||