help: make optlist local to subfunctions
authorMatt Mackall <mpm@selenic.com>
Sat, 17 Sep 2011 14:55:55 -0500
changeset 15129 9b904d679850
parent 15128 aaf666bd2942
child 15130 3d44e68360a6
help: make optlist local to subfunctions
mercurial/commands.py
--- a/mercurial/commands.py	Sat Sep 17 14:50:42 2011 -0500
+++ b/mercurial/commands.py	Sat Sep 17 14:55:55 2011 -0500
@@ -2661,7 +2661,6 @@
     Returns 0 if successful.
     """
 
-    optlist = []
     textwidth = min(ui.termwidth(), 80) - 2
 
     # list all option lists
@@ -2720,7 +2719,10 @@
 
         return text
 
-    def addglobalopts(aliases):
+    def addglobalopts(optlist, aliases):
+        if ui.quiet:
+            return []
+
         if ui.verbose:
             optlist.append((_("global options:"), globalopts))
             if name == 'shortlist':
@@ -2740,6 +2742,7 @@
             optlist.append((msg, ()))
 
     def helpcmd(name):
+        optlist = []
         try:
             aliases, entry = cmdutil.findcmd(name, table, strict=unknowncmd)
         except error.AmbiguousCommand, inst:
@@ -2791,8 +2794,6 @@
             if entry[1]:
                 optlist.append((_("options:\n"), entry[1]))
 
-            addglobalopts(False)
-
         # check if this command shadows a non-trivial (multi-line)
         # extension help text
         try:
@@ -2805,6 +2806,7 @@
         except KeyError:
             pass
 
+        addglobalopts(optlist, False)
         ui.write(opttext(optlist, textwidth))
 
     def helplist(select=None):
@@ -2853,9 +2855,6 @@
                                              initindent=' %-*s   ' % (m, f),
                                              hangindent=' ' * (m + 4))))
 
-        if not ui.quiet:
-            addglobalopts(True)
-
         if not name:
             text = help.listexts(_('enabled extensions:'), extensions.enabled())
             if text:
@@ -2869,6 +2868,8 @@
             for t, desc in topics:
                 ui.write(" %-*s  %s\n" % (topics_len, t, desc))
 
+        optlist = []
+        addglobalopts(optlist, True)
         ui.write(opttext(optlist, textwidth))
 
     def helptopic(name):