[PATCH 2 of 4] help: move some helper functions to help.py

Olav Reinert seroton10 at gmail.com
Tue May 22 15:11:41 CDT 2012


# HG changeset patch
# User Olav Reinert <seroton10 at gmail.com>
# Date 1337717321 -7200
# Node ID d00bbe12035ac97272e69a5208d11ebdaa46e79d
# Parent  dc0f31ff7a90acf5e2c71a9f17f873c9926224bf
help: move some helper functions to help.py

diff -r dc0f31ff7a90 -r d00bbe12035a mercurial/commands.py
--- a/mercurial/commands.py	Tue May 22 22:08:41 2012 +0200
+++ b/mercurial/commands.py	Tue May 22 22:08:41 2012 +0200
@@ -3089,56 +3089,6 @@
 
     textwidth = min(ui.termwidth(), 80) - 2
 
-    def optrst(options, verbose):
-        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 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\n")
-
-        return rst
-
-    # list all option lists
-    def opttext(optlist, width, verbose):
-        rst = ''
-        if not optlist:
-            return ''
-
-        for title, options in optlist:
-            rst += '\n%s\n' % title
-            if options:
-                rst += "\n"
-                rst += optrst(options, verbose)
-                rst += '\n'
-
-        return '\n' + minirst.format(rst, width)
-
     def addglobalopts(optlist, aliases):
         if ui.quiet:
             return []
@@ -3223,13 +3173,13 @@
             rst += '\n'
             rst += _("options:")
             rst += '\n\n'
-            rst += optrst(entry[1], ui.verbose)
+            rst += help.optrst(entry[1], ui.verbose)
 
         if ui.verbose:
             rst += '\n'
             rst += _("global options:")
             rst += '\n\n'
-            rst += optrst(globalopts, ui.verbose)
+            rst += help.optrst(globalopts, ui.verbose)
 
         keep = ui.verbose and ['verbose'] or []
         formatted, pruned = minirst.format(rst, textwidth, keep=keep)
@@ -3304,7 +3254,7 @@
 
         optlist = []
         addglobalopts(optlist, True)
-        ui.write(opttext(optlist, textwidth, ui.verbose))
+        ui.write(help.opttext(optlist, textwidth, ui.verbose))
 
     def helptopic(name):
         for names, header, doc in help.helptable:
diff -r dc0f31ff7a90 -r d00bbe12035a mercurial/help.py
--- a/mercurial/help.py	Tue May 22 22:08:41 2012 +0200
+++ b/mercurial/help.py	Tue May 22 22:08:41 2012 +0200
@@ -8,7 +8,7 @@
 from i18n import gettext, _
 import itertools, sys, os
 import extensions, revset, fileset, templatekw, templatefilters, filemerge
-import encoding, util
+import encoding, util, minirst
 
 def listexts(header, exts, indent=1):
     '''return a text listing of the given extensions'''
@@ -27,6 +27,56 @@
     doc += listexts(_('disabled extensions:'), extensions.disabled())
     return doc
 
+def optrst(options, verbose):
+    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 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\n")
+
+    return rst
+
+# list all option lists
+def opttext(optlist, width, verbose):
+    rst = ''
+    if not optlist:
+        return ''
+
+    for title, options in optlist:
+        rst += '\n%s\n' % title
+        if options:
+            rst += "\n"
+            rst += optrst(options, verbose)
+            rst += '\n'
+
+    return '\n' + minirst.format(rst, width)
+
 def topicmatch(kw):
     """Return help topics matching kw.
 


More information about the Mercurial-devel mailing list