]> arthur.barton.de Git - bup.git/blob - lib/cmd/help-cmd.py
c078e825c1f972afe5833196c65e1eaed5b4df2d
[bup.git] / lib / cmd / help-cmd.py
1 #!/bin/sh
2 """": # -*-python-*-
3 # https://sourceware.org/bugzilla/show_bug.cgi?id=26034
4 export "BUP_ARGV_0"="$0"
5 arg_i=1
6 for arg in "$@"; do
7     export "BUP_ARGV_${arg_i}"="$arg"
8     shift
9     arg_i=$((arg_i + 1))
10 done
11 # Here to end of preamble replaced during install
12 bup_python="$(dirname "$0")/bup-python" || exit $?
13 exec "$bup_python" "$0"
14 """
15 # end of bup preamble
16
17 from __future__ import absolute_import
18 import sys, os, glob
19 from bup import compat, options, path
20
21 optspec = """
22 bup help <command>
23 """
24 o = options.Options(optspec)
25 opt, flags, extra = o.parse(compat.argv[1:])
26
27 if len(extra) == 0:
28     # the wrapper program provides the default usage string
29     os.execvp(path.exe(), ['bup'])
30 elif len(extra) == 1:
31     docname = (extra[0]=='bup' and 'bup' or ('bup-%s' % extra[0]))
32     manpath = os.path.join(path.exedir(),
33                            'Documentation/' + docname + '.[1-9]')
34     g = glob.glob(manpath)
35     try:
36         if g:
37             os.execvp('man', ['man', '-l', g[0]])
38         else:
39             os.execvp('man', ['man', docname])
40     except OSError as e:
41         sys.stderr.write('Unable to run man command: %s\n' % e)
42         sys.exit(1)
43 else:
44     o.fatal("exactly one command name expected")