]> mj.ucw.cz Git - bex.git/blob - bex
Rename subcommands
[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 (l)          Show queues and jobs on them
28 mach            List known machines and groups
29 prun (pr)       Parallel version of `run'
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 if (!-f "$bex_lib/perl/BEX.pm") {
47         die "BEX library directory $bex_lib misconfigured.\n";
48 }
49
50 @ARGV or die "Missing subcommand.\n";
51 my $sub = shift @ARGV;
52 $sub =~ /^[0-9a-zA-Z]+$/ or die "Invalid subcommand $sub\n";
53
54 my %aliases = (
55         'a' => 'add',
56         'l' => 'ls',
57         'p' => 'prun',
58         'r' => 'run',
59 );
60 if (defined $aliases{$sub}) { $sub = $aliases{$sub}; }
61
62 my $sub_path = "$bex_lib/bin/$sub";
63 -x $sub_path or die "Unknown subcommand $sub\n";
64
65 $ENV{"BEX_HOME"} = $bex_home;
66 $ENV{"BEX_LIB"} = $bex_lib;
67 $ENV{"PERL5LIB"} = join(":", $bex_lib . "/perl", $ENV{"PERL5LIB"} // ());
68 exec $sub_path, @ARGV;
69 die "Cannot execute $sub_path: $!\n";