diff mercurial/commands.py @ 15145:ff26712a0c50

help: use RST to format option lists
author Matt Mackall <mpm@selenic.com>
date Wed, 21 Sep 2011 13:00:48 -0500
parents 0834e0bb445a
children 395ca8cd2669
line wrap: on
line diff
--- a/mercurial/commands.py	Wed Sep 21 13:00:47 2011 -0500
+++ b/mercurial/commands.py	Wed Sep 21 13:00:48 2011 -0500
@@ -2709,61 +2709,52 @@
 
     textwidth = min(ui.termwidth(), 80) - 2
 
+    def optrst(options):
+        data = []
+        multioccur = False
+        for option in options:
+            if len(option) == 5:
+                shortopt, longopt, default, desc, optlabel = option
+            else:
+                shortopt, longopt, default, desc = option
+                optlabel = _("VALUE") # default label
+
+            if _("DEPRECATED") in desc and not ui.verbose:
+                continue
+
+            so = ''
+            if shortopt:
+                so = '-' + shortopt
+            lo = '--' + longopt
+            if default:
+                desc += _(" (default: %s)") % default
+
+            if isinstance(default, list):
+                lo += " %s [+]" % optlabel
+                multioccur = True
+            elif (default is not None) and not isinstance(default, bool):
+                lo += " %s" % optlabel
+
+            data.append((so, lo, desc))
+
+        rst = minirst.maketable(data, 1)
+        if multioccur:
+            rst += _("\n[+] marked option can be specified multiple times")
+
+        return rst
+
     # list all option lists
     def opttext(optlist, width):
-        out = []
-        multioccur = False
+        rst = ''
+        if not optlist:
+            return ''
+
         for title, options in optlist:
-            out.append(("\n%s" % title, None))
-            for option in options:
-                if len(option) == 5:
-                    shortopt, longopt, default, desc, optlabel = option
-                else:
-                    shortopt, longopt, default, desc = option
-                    optlabel = _("VALUE") # default label
-
-                if _("DEPRECATED") in desc and not ui.verbose:
-                    continue
-                if isinstance(default, list):
-                    numqualifier = " %s [+]" % optlabel
-                    multioccur = True
-                elif (default is not None) and not isinstance(default, bool):
-                    numqualifier = " %s" % optlabel
-                else:
-                    numqualifier = ""
-                out.append(("%2s%s" %
-                            (shortopt and "-%s" % shortopt,
-                             longopt and " --%s%s" %
-                             (longopt, numqualifier)),
-                            "%s%s" % (desc,
-                                      default
-                                      and _(" (default: %s)") % default
-                                      or "")))
-        if multioccur:
-            msg = _("\n[+] marked option can be specified multiple times")
-            if ui.verbose and name != 'shortlist':
-                out.append((msg, None))
-            else:
-                out.insert(-1, (msg, None))
-
-        text = ""
-        if out:
-            colwidth = encoding.colwidth
-            # normalize: (opt or message, desc or None, width of opt)
-            entries = [desc and (opt, desc, colwidth(opt)) or (opt, None, 0)
-                       for opt, desc in out]
-            hanging = max([e[2] for e in entries])
-            for opt, desc, width in entries:
-                if desc:
-                    initindent = ' %s%s  ' % (opt, ' ' * (hanging - width))
-                    hangindent = ' ' * (hanging + 3)
-                    text += '%s\n' % (util.wrap(desc, width,
-                                                initindent=initindent,
-                                                hangindent=hangindent))
-                else:
-                    text +=  "%s\n" % opt
-
-        return text
+            rst += '\n%s\n\n' % title
+            rst += optrst(options)
+            rst += '\n'
+
+        return '\n' + minirst.format(rst, width)
 
     def addglobalopts(optlist, aliases):
         if ui.quiet: