]> arthur.barton.de Git - bup.git/commitdiff
main: list common commands before other ones.
authorAvery Pennarun <apenwarr@gmail.com>
Mon, 1 Mar 2010 00:00:50 +0000 (19:00 -0500)
committerAvery Pennarun <apenwarr@gmail.com>
Mon, 1 Mar 2010 00:00:50 +0000 (19:00 -0500)
When you just type 'bup' or 'bup help', we print a list of available
commands.  Now we improve this list by:

1) Listing the common commands (with one-line descriptions) before listing
the automatically-generated list.

2) Printing the automatically-generated list in columns, so it takes up less
vertical space.

This whole concept was stolen from how git does it.  I think it should be a
bit more user friendly for beginners this way.

main.py

diff --git a/main.py b/main.py
index 747e6867bcca40e3116336c4188b9aa204d89009..8cd22937bda207fd5a7afe859a9b7b9a502e999e 100755 (executable)
--- a/main.py
+++ b/main.py
@@ -13,16 +13,58 @@ os.environ['PYTHONPATH'] = libpath + ':' + os.environ.get('PYTHONPATH', '')
 
 from bup.helpers import *
 
+
+def columnate(l, prefix):
+    l = l[:]
+    clen = max(len(s) for s in l)
+    ncols = (78 - len(prefix)) / (clen + 2)
+    if ncols <= 1:
+        ncols = 1
+        clen = 0
+    cols = []
+    while len(l) % ncols:
+        l.append('')
+    rows = len(l)/ncols
+    for s in range(0, len(l), rows):
+        cols.append(l[s:s+rows])
+    for row in zip(*cols):
+        print prefix + ''.join(('%-*s' % (clen+2, s)) for s in row)
+
+
 def usage():
     log('Usage: bup <command> <options...>\n\n')
-    log('Available commands:\n')
+    common = dict(
+        ftp = 'Browse backup sets using an ftp-like client',
+        fsck = 'Check backup sets for damage and add redundancy information',
+        fuse = 'Mount your backup sets as a filesystem',
+        index = 'Create or display the index of files to back up',
+        join = 'The reverse operation to "bup split"',
+        ls = 'Browse the files in your backup sets',
+        midx = 'Index objects to speed up future backups',
+        save = 'Save files into a backup set (note: run "bup index" first)',
+        split = 'Split a single file into its own backup set',
+    )
+
+    log('Common commands:\n')
+    for cmd,synopsis in sorted(common.items()):
+        print '    %-10s %s' % (cmd, synopsis)
+    log('\n')
+    
+    log('Other available commands:\n')
+    cmds = []
     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 " +
+            cname = c[4:]
+            if cname not in common:
+                cmds.append(c[4:])
+    columnate(cmds, '    ')
+    log('\n')
+    
+    log("See '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()