| 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
| |||||||||||||||
| 18 | 4 | my $group = $1; | |||||||||||||
| 19 | 4 | ▶ | if ($group eq 'x') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 60 | 1 | print $msg; | |||||||||||||
| 61 | 1 | exit 0; | |||||||||||||
| 62 | } else { | ||||||||||||||
| 63 | 1 | warn $msg; | |||||||||||||
| 64 | 1 | exit $exit_code; | |||||||||||||
| 65 | } | ||||||||||||||
| 66 | } | ||||||||||||||
| 67 | |||||||||||||||
| 68 | __END__ | ||||||||||||||