b68a414ce7710622afb10e4a5c9e5db7b1e1cc28
[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
23 import sys
24 from libbe import cmdutil, _version
25
26 __doc__ == cmdutil.help()
27
28 if len(sys.argv) == 1 or sys.argv[1] in ('--help', '-h'):
29     print cmdutil.help()
30 elif sys.argv[1] == '--complete':
31     for command, module in cmdutil.iter_commands():
32         print command
33     print '\n'.join(["--help","--complete","--options","--version"])
34 elif sys.argv[1] == '--version':
35     print _version.version_info["revision_id"]
36 else:
37     try:
38         sys.exit(cmdutil.execute(sys.argv[1], sys.argv[2:]))
39     except cmdutil.GetHelp:
40         print cmdutil.help(sys.argv[1])
41         sys.exit(0)
42     except cmdutil.GetCompletions, e:
43         print '\n'.join(e.completions)
44         sys.exit(0)
45     except cmdutil.UnknownCommand, e:
46         print e
47         sys.exit(1)
48     except cmdutil.UsageError, e:
49         print "Invalid usage:", e
50         print "\nArgs:", sys.argv[1:]
51         print cmdutil.help(sys.argv[1])
52         sys.exit(1)
53     except cmdutil.UserError, e:
54         print "ERROR:"
55         print e
56         sys.exit(1)