#!/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;
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)
"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;