5bdd6b2ac5f7bff3190f943c33668a43686a72f9
[be.git] / be
1 #!/usr/bin/env python
2 # Copyright (C) 2005-2009 Aaron Bentley and Panometrics, Inc.
3 #                         Chris Ball <cjb@laptop.org>
4 #                         Oleg Romanyshyn <oromanyshyn@panoramicfeedback.com>
5 #                         W. Trevor King <wking@drexel.edu>
6 # <abentley@panoramicfeedback.com>
7 #
8 #    This program is free software; you can redistribute it and/or modify
9 #    it under the terms of the GNU General Public License as published by
10 #    the Free Software Foundation; either version 2 of the License, or
11 #    (at your option) any later version.
12 #
13 #    This program is distributed in the hope that it will be useful,
14 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #    GNU General Public License for more details.
17 #
18 #    You should have received a copy of the GNU General Public License
19 #    along with this program; if not, write to the Free Software
20 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
22 import sys
23
24 from libbe import cmdutil, _version
25
26 __doc__ = cmdutil.help()
27
28 usage = "be [options] [command] [command_options ...] [command_args ...]"
29
30 parser = cmdutil.CmdOptionParser(usage)
31 parser.command = "be"
32 parser.add_option("--version", action="store_true", dest="version",
33                   help="Print version string and exit")
34
35 try:
36     options,args = parser.parse_args()
37 except cmdutil.GetHelp:
38     print cmdutil.help(parser=parser)
39     sys.exit(0)
40 except cmdutil.GetCompletions, e:
41     print '\n'.join(e.completions)
42     sys.exit(0)
43
44 if options.version == True:
45     print _version.version_info["revision_id"]
46     sys.exit(0)
47
48 try:
49     if len(args) == 0:
50         raise cmdutil.UsageError, "must supply a command"
51     sys.exit(cmdutil.execute(args[0], args[1:]))
52 except cmdutil.GetHelp:
53     print cmdutil.help(sys.argv[1])
54     sys.exit(0)
55 except cmdutil.GetCompletions, e:
56     print '\n'.join(e.completions)
57     sys.exit(0)
58 except cmdutil.UnknownCommand, e:
59     print e
60     sys.exit(1)
61 except cmdutil.UsageError, e:
62     print "Invalid usage:", e
63     if len(args) == 0:
64         print cmdutil.help(parser=parser)
65     else:
66         print "\nArgs:", args
67         print cmdutil.help(sys.argv[1])
68     sys.exit(1)
69 except cmdutil.UserError, e:
70     print "ERROR:"
71     print e
72     sys.exit(1)