diff mercurial/commands.py @ 4315:bc6f5a1d8b7b

Add a pointer to "hg -v help" to the bottom of hg help {,cmd} output This should make it easier to discover global options. As a bonus, they are no longer displayed by something like a hg -v help dates
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Sat, 07 Apr 2007 04:27:55 -0300
parents 8185a1ca8628
children 38922a13101e
line wrap: on
line diff
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1268,6 +1268,23 @@ def help_(ui, name=None, with_version=Fa
     commands it provides."""
     option_lists = []
 
+    def addglobalopts(aliases):
+        if ui.verbose:
+            option_lists.append((_("global options:"), globalopts))
+            if name == 'shortlist':
+                option_lists.append((_('use "hg help" for the full list '
+                                       'of commands'), ()))
+        else:
+            if name == 'shortlist':
+                msg = _('use "hg help" for the full list of commands '
+                        'or "hg -v" for details')
+            elif aliases:
+                msg = _('use "hg -v help%s" to show aliases and '
+                        'global options') % (name and " " + name or "")
+            else:
+                msg = _('use "hg -v help %s" to show global options') % name
+            option_lists.append((msg, ()))
+
     def helpcmd(name):
         if with_version:
             version_(ui)
@@ -1291,7 +1308,9 @@ def help_(ui, name=None, with_version=Fa
 
             # options
             if i[1]:
-                option_lists.append(("options", i[1]))
+                option_lists.append((_("options:\n"), i[1]))
+
+            addglobalopts(False)
 
     def helplist(select=None):
         h = {}
@@ -1321,6 +1340,9 @@ def help_(ui, name=None, with_version=Fa
             else:
                 ui.write(' %-*s   %s\n' % (m, f, h[f]))
 
+        if not ui.quiet:
+            addglobalopts(True)
+
     def helptopic(name):
         v = None
         for i in help.helptable:
@@ -1360,12 +1382,7 @@ def help_(ui, name=None, with_version=Fa
             ui.status(_('no commands defined\n'))
             return
 
-        if ui.verbose:
-            ui.status(_('list of commands:\n\n'))
-        else:
-            ui.status(_('list of commands (use "hg help -v %s" '
-                        'to show aliases and global options):\n\n') % name)
-
+        ui.status(_('list of commands:\n\n'))
         modcmds = dict.fromkeys([c.split('|', 1)[0] for c in ct])
         helplist(modcmds.has_key)
 
@@ -1391,24 +1408,16 @@ def help_(ui, name=None, with_version=Fa
 
         # list of commands
         if name == "shortlist":
-            ui.status(_('basic commands (use "hg help" '
-                        'for the full list or option "-v" for details):\n\n'))
-        elif ui.verbose:
+            ui.status(_('basic commands:\n\n'))
+        else:
             ui.status(_('list of commands:\n\n'))
-        else:
-            ui.status(_('list of commands (use "hg help -v" '
-                        'to show aliases and global options):\n\n'))
 
         helplist()
 
-    # global options
-    if ui.verbose:
-        option_lists.append(("global options", globalopts))
-
     # list all option lists
     opt_output = []
     for title, options in option_lists:
-        opt_output.append(("\n%s:\n" % title, None))
+        opt_output.append(("\n%s" % title, None))
         for shortopt, longopt, default, desc in options:
             if "DEPRECATED" in desc and not ui.verbose: continue
             opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt,
@@ -1419,7 +1428,7 @@ def help_(ui, name=None, with_version=Fa
                                          or "")))
 
     if opt_output:
-        opts_len = max([len(line[0]) for line in opt_output if line[1]])
+        opts_len = max([len(line[0]) for line in opt_output if line[1]] or [0])
         for first, second in opt_output:
             if second:
                 ui.write(" %-*s  %s\n" % (opts_len, first, second))