bin/fornodes

filter: Statementstmt 97.3% 37 / 38 Branchbran 91.6% 11 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 96.3% 53 / 55 CC 2 SCAR 2.9
CC
2
Cov
96%
help
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
« bin/tonodes ↑ Summary
1 #!/usr/bin/env perl
2  
3 42 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 42 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 #use Smart::Comments::JSON '##';
7 42 ▶use lib 'lib';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 42 ▶use SSH::Batch::ForNodes;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 sub help ($);
11  
12 42 SSH::Batch::ForNodes::init_rc();
13  
14 41 my $expand_list;
15 my @args;
16 41 for (@ARGV) {
17 44 ▶ if (/^-(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^-(.*)/) { } 4 40 44
18 4 my $group = $1;
19 4 ▶ if ($group eq 'x') {
Branch: 2 branches
BranchTrueFalseTotal
if ($group eq 'x') { } 3 1 4
elsif ($group eq 'h') { } 1 0 1
20 3 $expand_list = 1;
21 } elsif ($group eq 'h') {
22 1 help(0);
23 } else {
24 0 die "ERROR: Unknown option $_\n";
25 }
26 } else {
27 40 push @args, $_;
28 }
29 }
30  
31 ## @ARGV
32 40 my $expr = join ' ', @args;
33 40 ▶if (!$expr) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($expr) 1 39 40
34 1 warn "No argument specified.\n\n";
35 1 help(1);
36 }
37  
38 39 my $set = SSH::Batch::ForNodes::parse_expr($expr);
39  
40 35 ▶if ($expand_list) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expand_list) { } 3 32 35
41 3 for my $host (sort $set->elements) {
42 37 print $host, "\n";
43 }
44 } else {
45 32 print join(' ', sort $set->elements), "\n";
46 }
47  
48 sub help ($) {
49 2 ▶ my $exit_code = shift;
Subroutine help: called CC=2 SCAR=6.9
50 2 my $msg = <<'_EOC_';
51 USAGE:
52  
53 fornodes [OPTIONS] HOST_PATTERN... [OPTIONS]
54  
55 OPTIONS:
56 -h Print this help
57 -x Expand the host list output to multiple lines.
58 _EOC_
59 2 ▶ if ($exit_code == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exit_code == 0) { } 1 1 2
60 1 print $msg;
61 1 exit 0;
62 } else {
63 1 warn $msg;
64 1 exit $exit_code;
65 }
66 }
67  
68 __END__
« bin/tonodes ↑ Summary