]> arthur.barton.de Git - bup.git/blob - cmd/help-cmd.py
Simplify bup startup process
[bup.git] / cmd / help-cmd.py
1 #!/bin/sh
2 """": # -*-python-*-
3 bup_python="$(dirname "$0")/bup-python" || exit $?
4 exec "$bup_python" "$0" ${1+"$@"}
5 """
6 # end of bup preamble
7
8 from __future__ import absolute_import
9 import sys, os, glob
10 from bup import options, path
11
12 optspec = """
13 bup help <command>
14 """
15 o = options.Options(optspec)
16 (opt, flags, extra) = o.parse(sys.argv[1:])
17
18 if len(extra) == 0:
19     # the wrapper program provides the default usage string
20     os.execvp(path.exe(), ['bup'])
21 elif len(extra) == 1:
22     docname = (extra[0]=='bup' and 'bup' or ('bup-%s' % extra[0]))
23     manpath = os.path.join(path.exedir(),
24                            'Documentation/' + docname + '.[1-9]')
25     g = glob.glob(manpath)
26     try:
27         if g:
28             os.execvp('man', ['man', '-l', g[0]])
29         else:
30             os.execvp('man', ['man', docname])
31     except OSError as e:
32         sys.stderr.write('Unable to run man command: %s\n' % e)
33         sys.exit(1)
34 else:
35     o.fatal("exactly one command name expected")