]> arthur.barton.de Git - bup.git/blob - lib/cmd/help-cmd.py
Prefer python 3, and mention intent to drop python 2 support
[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")/../../config/bin/python" || exit $?
13 exec "$bup_python" "$0"
14 """
15 # end of bup preamble
16
17 from __future__ import absolute_import
18 import os, glob, sys
19
20 sys.path[:0] = [os.path.dirname(os.path.realpath(__file__)) + '/..']
21
22 from bup import compat, options, path
23 from bup.compat import argv_bytes
24
25
26 optspec = """
27 bup help <command>
28 """
29 o = options.Options(optspec)
30 opt, flags, extra = o.parse(compat.argv[1:])
31
32 if len(extra) == 0:
33     # the wrapper program provides the default usage string
34     os.execvp(path.exe(), [b'bup'])
35 elif len(extra) == 1:
36     docname = (extra[0]=='bup' and b'bup' or (b'bup-%s' % argv_bytes(extra[0])))
37     manpath = os.path.join(path.exedir(),
38                            b'../../Documentation/' + docname + b'.[1-9]')
39     g = glob.glob(manpath)
40     try:
41         if g:
42             os.execvp('man', ['man', '-l', g[0]])
43         else:
44             os.execvp('man', ['man', docname])
45     except OSError as e:
46         sys.stderr.write('Unable to run man command: %s\n' % e)
47         sys.exit(1)
48 else:
49     o.fatal("exactly one command name expected")