From: Martin Mares Date: Thu, 11 Jul 2019 12:34:51 +0000 (+0200) Subject: "bex mach" can be asked for a set of machines X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;ds=sidebyside;h=546b0a3f1bae4c6761525587537a21fc2f87fed4;p=bex.git "bex mach" can be asked for a set of machines I changed the default: when called with no arguments, it prints all known machines. Groups are printed only when asked for. --- diff --git a/lib/bin/bex-mach b/lib/bin/bex-mach index 7301fa9..d212349 100755 --- a/lib/bin/bex-mach +++ b/lib/bin/bex-mach @@ -1,6 +1,6 @@ #!/usr/bin/perl # Batch EXecutor -- List Machines and Groups -# (c) 2011-2012 Martin Mares +# (c) 2011-2019 Martin Mares use strict; use warnings; @@ -12,37 +12,48 @@ my $queue_name; sub usage() { print <] +Usage: bex mach [] [[!] ...] Options: +--groups List groups instead of machines None defined so far. AMEN exit 0; } +my $groups; + GetOptions( "help" => \&usage, -) && @ARGV == 0 or die "Try `bex mach --help' for more information.\n"; + "groups!" => \$groups, +) or die "Try `bex mach --help' for more information.\n"; my $machines = \%BEX::Config::machines; -print "# Hosts:\n"; -for my $h (sort keys %$machines) { - my $m = $machines->{$h}; - ref $m eq 'HASH' or next; - print "$h\n"; -} +if ($groups) { + !@ARGV or die "bex mach --groups accepts no positional arguments.\n"; + for my $h (sort keys %$machines) { + my $m = $machines->{$h}; + ref $m eq 'ARRAY' or next; + print "$h = ", join(" ", + map { + my $x = $machines->{$_}; + !defined($x) ? "$_?" : + ref $x eq 'HASH' ? $_ : + ref $x eq 'ARRAY' ? "\@$_" : + "$_???" + } @$m), "\n"; + } +} elsif (@ARGV) { + my @machines = BEX::Config::parse_machine_list(@ARGV); + for my $m (sort @machines) { + print "$m\n"; + } +} else { + for my $h (sort keys %$machines) { + my $m = $machines->{$h}; + ref $m eq 'HASH' or next; + print "$h\n"; + } -print "\n# Groups:\n"; -for my $h (sort keys %$machines) { - my $m = $machines->{$h}; - ref $m eq 'ARRAY' or next; - print "$h = ", join(" ", - map { - my $x = $machines->{$_}; - !defined($x) ? "$_?" : - ref $x eq 'HASH' ? $_ : - ref $x eq 'ARRAY' ? "\@$_" : - "$_???" - } @$m), "\n"; }