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