Adjust display and alignment of command options to match global options.
authorThomas Arendsen Hein <thomas@intevation.de>
Fri, 26 Aug 2005 09:56:33 +0200
changeset 1052 d8279ca39dc7
parent 1051 3c918b7ad8da
child 1053 1539ca091d86
Adjust display and alignment of command options to match global options.
mercurial/commands.py
tests/test-help.out
--- a/mercurial/commands.py	Fri Aug 26 09:15:04 2005 +0200
+++ b/mercurial/commands.py	Fri Aug 26 09:56:33 2005 +0200
@@ -271,6 +271,7 @@
 
 def help_(ui, cmd=None, with_version=False):
     """show help for a given command or all commands"""
+    option_lists = []
     if cmd and cmd != 'shortlist':
         if with_version:
             show_version(ui)
@@ -285,26 +286,15 @@
             doc = doc.splitlines(0)[0]
         ui.write("%s\n" % doc.rstrip())
 
-        # aliases
         if not ui.quiet:
+            # aliases
             aliases = ', '.join(key.split('|')[1:])
             if aliases:
                 ui.write("\naliases: %s\n" % aliases)
 
-        # options
-        if not ui.quiet and i[1]:
-            ui.write("\noptions:\n\n")
-            for s, l, d, c in i[1]:
-                opt = ' '
-                if s:
-                    opt = opt + '-' + s + ' '
-                if l:
-                    opt = opt + '--' + l + ' '
-                if d:
-                    opt = opt + '(' + str(d) + ')'
-                ui.write(opt, "\n")
-                if c:
-                    ui.write('   %s\n' % c)
+            # options
+            if i[1]:
+                option_lists.append(("options", i[1]))
 
     else:
         # program name
@@ -351,16 +341,26 @@
 
     # global options
     if ui.verbose:
-        ui.write("\nglobal options:\n\n")
-        opts, descriptions = [], []
-        for shortopt, longopt, default, desc in globalopts:
-            opts.append("%2s%s" %
-                        (shortopt and "-%s" % shortopt,
-                         longopt and " --%s" % longopt))
-            descriptions.append(desc)
-        opts_len = max(map(len, opts))
-        for opt, desc in zip(opts, descriptions):
-            ui.write(" %-*s  %s\n" % (opts_len, opt, desc))
+        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))
+        for shortopt, longopt, default, desc in options:
+            opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt,
+                                          longopt and " --%s" % longopt),
+                               "%s%s" % (desc,
+                                         default and " (default: %s)" % default
+                                         or "")))
+
+    if opt_output:
+        opts_len = max([len(line[0]) for line in opt_output if line[1]])
+        for first, second in opt_output:
+            if second:
+                ui.write(" %-*s  %s\n" % (opts_len, first, second))
+            else:
+                ui.write("%s\n" % first)
 
 # Commands start here, listed alphabetically
 
--- a/tests/test-help.out	Fri Aug 26 09:15:04 2005 +0200
+++ b/tests/test-help.out	Fri Aug 26 09:56:33 2005 +0200
@@ -118,10 +118,8 @@
 
 options:
 
- -I --include 
-   include path in search
- -X --exclude 
-   exclude path from search
+ -I --include  include path in search
+ -X --exclude  exclude path from search
 hg add: option --skjdfks not recognized
 hg add [OPTION]... [FILE]...
 
@@ -129,24 +127,18 @@
 
 options:
 
- -I --include 
-   include path in search
- -X --exclude 
-   exclude path from search
+ -I --include  include path in search
+ -X --exclude  exclude path from search
 hg diff [-I] [-X] [-r REV1 [-r REV2]] [FILE]...
 
 diff working directory (or selected files)
 
 options:
 
- -r --rev 
-   revision
- -a --text 
-   treat all files as text
- -I --include 
-   include path in search
- -X --exclude 
-   exclude path from search
+ -r --rev      revision
+ -a --text     treat all files as text
+ -I --include  include path in search
+ -X --exclude  exclude path from search
 hg status [OPTION]... [FILE]...
 
 show changed files in the working directory
@@ -158,18 +150,12 @@
 
 options:
 
- -m --modified 
-   show only modified files
- -a --added 
-   show only added files
- -r --removed 
-   show only removed files
- -u --unknown 
-   show only unknown (not tracked) files
- -I --include 
-   include path in search
- -X --exclude 
-   exclude path from search
+ -m --modified  show only modified files
+ -a --added     show only added files
+ -r --removed   show only removed files
+ -u --unknown   show only unknown (not tracked) files
+ -I --include   include path in search
+ -X --exclude   exclude path from search
 hg status [OPTION]... [FILE]...
 
 show changed files in the working directory