1#!/bin/sh
2"""": # -*-python-*-
3# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
4export "BUP_ARGV_0"="$0"
5arg_i=1
6for arg in "$@"; do
7    export "BUP_ARGV_${arg_i}"="$arg"
8    shift
9    arg_i=$((arg_i + 1))
10done
11# Here to end of preamble replaced during install
12bup_python="$(dirname "$0")/../../config/bin/python" || exit $?
13exec "$bup_python" "$0"
14"""
15# end of bup preamble
16
17from __future__ import absolute_import
18import os, glob, sys
19
20sys.path[:0] = [os.path.dirname(os.path.realpath(__file__)) + '/..']
21
22from bup import compat, options, path
23from bup.compat import argv_bytes
24
25
26optspec = """
27bup help <command>
28"""
29o = options.Options(optspec)
30opt, flags, extra = o.parse(compat.argv[1:])
31
32if len(extra) == 0:
33    # the wrapper program provides the default usage string
34    os.execvp(path.exe(), [b'bup'])
35elif 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)
48else:
49    o.fatal("exactly one command name expected")
50