Expand uses of ranges

Ranges can now be used on:

Ports:
        cssh localhost:{22001..22008}

FQDN's:
        cssh host{10..20}.domain.name

IP's:
        cssh 192.168.10.{10..20}
This commit is contained in:
Duncan Ferguson 2017-05-17 22:35:46 +01:00
parent 34f6c3e77d
commit f1446f9be3
3 changed files with 18 additions and 3 deletions

View file

@ -54,7 +54,7 @@ Ranges are of the form:
sub expand {
my ( $self, @items ) = @_;
my $range_regexp = qr/^[\w-]+\{[\w\.,]+\}$/;
my $range_regexp = qr/[\w-]*:?\{[\w\.,]+\}/;
my @newlist;
foreach my $item (@items) {
if ( $item !~ m/$range_regexp/ ) {
@ -62,7 +62,7 @@ sub expand {
next;
}
my ( $base, $spec ) = $item =~ m/^(.*)?\{(.*)\}$/;
my ( $base, $spec ) = $item =~ m/^(.*?\{(.*)\}.*?)$/;
for my $section ( split( /,/, $spec ) ) {
my ( $start, $end );
@ -75,7 +75,8 @@ sub expand {
$end = $start if ( !defined($end) );
foreach my $number ( $start .. $end ) {
push( @newlist, "$base$number" );
( my $changed = $base ) =~ s/\{$spec\}/$number/;
push( @newlist, $changed );
}
}
}