]> arthur.barton.de Git - bup.git/commitdiff
Add a 'bup help' command.
authorAvery Pennarun <apenwarr@gmail.com>
Sun, 28 Feb 2010 23:28:04 +0000 (18:28 -0500)
committerAvery Pennarun <apenwarr@gmail.com>
Sun, 28 Feb 2010 23:30:11 +0000 (18:30 -0500)
It works like 'git help xxx', ie. it runs 'man bup-xxx' where xxx is the
command name.

cmd/help-cmd.py [new file with mode: 0755]
main.py

diff --git a/cmd/help-cmd.py b/cmd/help-cmd.py
new file mode 100755 (executable)
index 0000000..e95edfe
--- /dev/null
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+import sys, os, glob
+from bup import options
+
+optspec = """
+bup help <command>
+"""
+o = options.Options('bup help', optspec)
+(opt, flags, extra) = o.parse(sys.argv[1:])
+
+if len(extra) == 0:
+    # the wrapper program provides the default usage string
+    os.execvp('bup', ['bup'])
+elif len(extra) == 1:
+    docname = 'bup-%s' % extra[0]
+    exe = sys.argv[0]
+    (exepath, exefile) = os.path.split(exe)
+    manpath = os.path.join(exepath, '../Documentation/' + docname + '.[1-9]')
+    g = glob.glob(manpath)
+    if g:
+        os.execvp('man', ['man', '-l', g[0]])
+    else:
+        os.execvp('man', ['man', docname])
+else:
+    o.fatal("exactly one command name expected")
diff --git a/main.py b/main.py
index 36f65443d2aa67f5012562321b541f74e6568e82..747e6867bcca40e3116336c4188b9aa204d89009 100755 (executable)
--- a/main.py
+++ b/main.py
@@ -14,19 +14,19 @@ os.environ['PYTHONPATH'] = libpath + ':' + os.environ.get('PYTHONPATH', '')
 from bup.helpers import *
 
 def usage():
-    log('Usage: bup <subcmd> <options...>\n\n')
-    log('Available subcommands:\n')
+    log('Usage: bup <command> <options...>\n\n')
+    log('Available commands:\n')
     for c in sorted(os.listdir(cmdpath) + os.listdir(exepath)):
         if c.startswith('bup-') and c.find('.') < 0:
             log('\t%s\n' % c[4:])
+    log("\nSee 'bup help <command>' for more information on " +
+        "a specific command.\n")
     sys.exit(99)
 
 if len(argv) < 2 or not argv[1] or argv[1][0] == '-':
     usage()
 
 subcmd = argv[1]
-if subcmd == 'help':
-    usage()
 
 def subpath(s):
     sp = os.path.join(exepath, 'bup-%s' % s)
@@ -40,7 +40,7 @@ if not os.path.exists(subpath(subcmd)):
 
 
 already_fixed = atoi(os.environ.get('BUP_FORCE_TTY'))
-if subcmd in ['ftp']:
+if subcmd in ['ftp', 'help']:
     already_fixed = True
 fix_stdout = not already_fixed and os.isatty(1)
 fix_stderr = not already_fixed and os.isatty(2)