]> mj.ucw.cz Git - bex.git/blobdiff - lib/bin/bex-job
Accept partial job IDs as long as they are unique
[bex.git] / lib / bin / bex-job
index 3f10779e2f939ac8fac5ff0329ef905b00c499df..06f0e1394021c8bf0f5962f792bb3086678354f1 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 # Batch EXecutor -- Operations on a Job
-# (c) 2011-2012 Martin Mares <mj@ucw.cz>
+# (c) 2011-2015 Martin Mares <mj@ucw.cz>
 
 use strict;
 use warnings;
@@ -12,7 +12,7 @@ my $queue_name;
 
 sub usage() {
        print <<AMEN ;
-Usage: bex job [<options>] <job-id>
+Usage: bex job [<options>] [<job-id>]
 
 Options:
 -e, --edit             Run editor on the given job (no locking)
@@ -25,11 +25,20 @@ GetOptions(
        "e|edit!" => \$edit,
        "q|queue=s" => \$queue_name,
        "help" => \&usage,
-) && @ARGV == 1 or die "Try `bex job --help' for more information.\n";
+) && @ARGV <= 1 or die "Try `bex job --help' for more information.\n";
 
 my $queue = BEX::Queue->new($queue_name);
-my $fn = $queue->job_file($ARGV[0]);
--f $fn or die "No such job " . $ARGV[0] . "\n";
+
+if (!@ARGV) {
+       my @jobs = $queue->all_job_ids;
+       for (sort @jobs) {
+               print $_, "\n";
+       }
+       exit 0;
+}
+
+my $jid = $queue->resolve_job_id($ARGV[0]);
+my $fn = $queue->job_file($jid);
 
 if ($edit) {
        system "editor", $fn;