]> mj.ucw.cz Git - bex.git/blob - lib/bin/bex-job
Accept partial job IDs as long as they are unique
[bex.git] / lib / bin / bex-job
1 #!/usr/bin/perl
2 # Batch EXecutor -- Operations on a Job
3 # (c) 2011-2015 Martin Mares <mj@ucw.cz>
4
5 use strict;
6 use warnings;
7 use Getopt::Long;
8 use BEX;
9
10 my $edit;
11 my $queue_name;
12
13 sub usage() {
14         print <<AMEN ;
15 Usage: bex job [<options>] [<job-id>]
16
17 Options:
18 -e, --edit              Run editor on the given job (no locking)
19 -q, --queue=<name>      Act on the given queue
20 AMEN
21         exit 0;
22 }
23
24 GetOptions(
25         "e|edit!" => \$edit,
26         "q|queue=s" => \$queue_name,
27         "help" => \&usage,
28 ) && @ARGV <= 1 or die "Try `bex job --help' for more information.\n";
29
30 my $queue = BEX::Queue->new($queue_name);
31
32 if (!@ARGV) {
33         my @jobs = $queue->all_job_ids;
34         for (sort @jobs) {
35                 print $_, "\n";
36         }
37         exit 0;
38 }
39
40 my $jid = $queue->resolve_job_id($ARGV[0]);
41 my $fn = $queue->job_file($jid);
42
43 if ($edit) {
44         system "editor", $fn;
45 } else {
46         system "cat", $fn;
47 }