]> mj.ucw.cz Git - bex.git/blob - bex
Updated command usage
[bex.git] / bex
1 #!/usr/bin/perl
2 # Batch EXecutor 3.0 -- Master Program
3 # (c) 2012 Martin Mares <mj@ucw.cz>
4
5 use strict;
6 use warnings;
7 use Getopt::Long;
8
9 my $bex_home = $ENV{"BEX_HOME"} // ".";
10 my $bex_lib = $ENV{"BEX_LIB"} // "lib";
11
12 Getopt::Long::Configure('require_order');
13 GetOptions(
14         "home=s" => \$bex_home,
15         "lib=s" => \$bex_lib,
16         "help" => sub {
17                         print <<AMEN ;
18 Usage: bex <general-options> <command> <command-options> <args>
19
20 General options:
21 --home=<dir>    Home directory where all queues and config files reside
22 --lib=<dir>     Directory where BEX modules are installed
23
24 Commands (and aliases):
25 add (a)         Add new jobs to a queue
26 job             Operations on queued jobs
27 ls              List known machines and groups
28 prun (pr)       Parallel version of `run'
29 queue (q)       Show queues and jobs
30 run (r)         Run queued jobs
31 AMEN
32                         exit 0;
33                 },
34         "version" => sub {
35                         print "BEX 3.0 (c) 2011-2012 Martin Mares <mj\@ucw.cz>\n";
36                 },
37 ) or die "Try `bex --help' for more information.\n";
38 Getopt::Long::Configure('default');
39
40 if (!-d $bex_home) {
41         die "BEX home directory $bex_home does not exist.\n";
42 }
43 if (!-d "$bex_home/BEX") {
44         die "BEX home directory $bex_home does not contain the BEX subdirectory.\n";
45 }
46
47 @ARGV or die "Missing subcommand.\n";
48 my $sub = shift @ARGV;
49 $sub =~ /^[0-9a-zA-Z]+$/ or die "Invalid subcommand $sub\n";
50
51 my %aliases = (
52         'a' => 'add',
53         'p' => 'prun',
54         'q' => 'queue',
55         'r' => 'run',
56 );
57 if (defined $aliases{$sub}) { $sub = $aliases{$sub}; }
58
59 my $sub_path = "$bex_lib/bin/$sub";
60 -x $sub_path or die "Unknown subcommand $sub\n";
61
62 $ENV{"BEX_HOME"} = $bex_home;
63 $ENV{"BEX_LIB"} = $bex_lib;
64 $ENV{"PERL5LIB"} = join(":", $bex_lib . "/perl", $ENV{"PERL5LIB"} // ());
65 exec $sub_path, @ARGV;
66 die "Cannot execute $sub_path: $!\n";