]> mj.ucw.cz Git - bex.git/commitdiff
`bex queue' has its own subcommands
authorMartin Mares <mj@ucw.cz>
Wed, 15 Feb 2012 22:46:59 +0000 (23:46 +0100)
committerMartin Mares <mj@ucw.cz>
Wed, 15 Feb 2012 22:46:59 +0000 (23:46 +0100)
lib/bin/queue

index 2fb46fa375cffff825e29a1a5877d639292f8721..170ba50a36cc23a2c4cf09c1cba7c5136361130f 100755 (executable)
@@ -11,23 +11,35 @@ my $init;
 
 GetOptions(
        "init!" => \$init,
-) && @ARGV == 1 or die <<AMEN ;
-Usage: bex queue [<options>] <queue>
+) && @ARGV or die <<AMEN ;
+Usage: bex queue [<options>] <subcommand>
+
+Subcommands:
+init <queue>   Create a new queue
+ls             List all queues
 
 Options:
---init                 Create a new queue
+None defined so far.
 AMEN
 
-my $queue_name = shift @ARGV;
+my $op = shift @ARGV;
 
-if ($init) {
+if ($op eq 'init') {
+       my $queue_name = shift @ARGV or die "bex queue init requires a queue name\n";
        my $path = $BEX::Config::home . '/' . $queue_name;
        -d $path and die "Queue directory $path already exists\n";
        mkdir $path;
        mkdir "$path/hosts";
        mkdir "$path/jobs";
        print "Queue $queue_name initialized.\n";
+} elsif ($op eq 'ls' && @ARGV == 0) {
+       opendir D, $BEX::Config::home or die "Cannot read BEX home directory\n";
+       for my $q (sort readdir D) {
+               if (-d $q && -d "$q/hosts" && -d "$q/jobs") {
+                       print "$q\n";
+               }
+       }
+       closedir D;
 } else {
-       my $queue = BEX::Queue->new($queue_name);
-       print "Queue $queue is OK\n";
+       die "Invalid subcommand\n";
 }