Merge from BOS, fix help
authormpm@selenic.com
Fri, 26 Aug 2005 01:56:49 -0700
changeset 1060 e453d2053b2e
parent 1055 ea465485f54f (diff)
parent 1059 4eab07ef66e2 (current diff)
child 1061 fed8d078840b
Merge from BOS, fix help
mercurial/commands.py
tests/test-help.out
--- a/doc/hg.1.txt	Thu Aug 25 17:13:48 2005 -0700
+++ b/doc/hg.1.txt	Fri Aug 26 01:56:49 2005 -0700
@@ -207,7 +207,7 @@
 
     options:
     -p, --strip <n>   directory strip option for patch. This has the same
-                      meaning as the correnponding patch option
+                      meaning as the corresponding patch option
     -b <path>         base directory to read patches from
     -f, --force	      skip check for outstanding uncommitted changes
 
@@ -354,7 +354,7 @@
 remove [files ...]::
     Schedule the indicated files for removal from the repository.
     
-    This command shedules the files to be removed at the next commit.
+    This command schedules the files to be removed at the next commit.
     This only removes files from the current branch, not from the
     entire project history.
 
@@ -529,7 +529,7 @@
 
     Regexp examples:
 
-    re:.*\.c$      any name ending in ".c", anywhere in the repsitory
+    re:.*\.c$      any name ending in ".c", anywhere in the repository
 
 
 SPECIFYING SINGLE REVISIONS
@@ -623,7 +623,7 @@
 
  .hgtags::
     This file contains changeset hash values and text tag names (one of each
-    seperated by spaces) that correspond to tagged versions of the repository
+    separated by spaces) that correspond to tagged versions of the repository
     contents.
 
  /etc/mercurial/hgrc, $HOME/.hgrc, .hg/hgrc::
--- a/mercurial/commands.py	Thu Aug 25 17:13:48 2005 -0700
+++ b/mercurial/commands.py	Fri Aug 26 01:56:49 2005 -0700
@@ -343,9 +343,13 @@
         "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
     )
 
-def help_(ui, cmd=None):
+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)
+            ui.write('\n')
         key, i = find(cmd)
         # synopsis
         ui.write("%s\n\n" % i[2])
@@ -356,30 +360,19 @@
             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
-        if ui.verbose:
+        if ui.verbose or with_version:
             show_version(ui)
         else:
             ui.status("Mercurial Distributed SCM\n")
@@ -422,18 +415,26 @@
 
     # global options
     if ui.verbose:
-        ui.write("\nglobal options:\n\n")
-        for s, l, d, c in globalopts:
-            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)
+        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
 
@@ -668,6 +669,7 @@
         raise util.Abort(".hg/dirstate inconsistent with current parent's manifest")
 
 def debugconfig(ui):
+    """show combined config settings from all hgrc files"""
     try:
         repo = hg.repository(ui)
     except: pass
@@ -714,6 +716,7 @@
     ui.write("}\n")
 
 def debugwalk(ui, repo, *pats, **opts):
+    """show how files match on given patterns"""
     items = list(walk(repo, pats, opts))
     if not items: return
     fmt = '%%s  %%-%ds  %%-%ds  %%s\n' % (
@@ -791,6 +794,7 @@
     repo.forget(forget)
 
 def grep(ui, repo, pattern = None, *pats, **opts):
+    """search for a pattern in specified files and revisions"""
     if pattern is None: pattern = opts['regexp']
     if not pattern: raise util.Abort('no pattern to search for')
     reflags = 0
@@ -1475,7 +1479,7 @@
          [('U', 'noupdate', None, 'skip update after cloning'),
           ('e', 'ssh', "", 'ssh command'),
           ('', 'remotecmd', "", 'remote hg command')],
-         'hg clone [OPTIONS] SOURCE [DEST]'),
+         'hg clone [OPTION]... SOURCE [DEST]'),
     "^commit|ci":
         (commit,
          [('A', 'addremove', None, 'run add/remove during commit'),
@@ -1505,12 +1509,12 @@
           ('a', 'text', None, 'treat all files as text'),
           ('I', 'include', [], 'include path in search'),
           ('X', 'exclude', [], 'exclude path from search')],
-         'hg diff [-I] [-X] [-r REV1 [-r REV2]] [FILE]...'),
+         'hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...'),
     "^export":
         (export,
          [('o', 'output', "", 'output to file'),
           ('a', 'text', None, 'treat all files as text')],
-         "hg export [-o OUTFILE] REV..."),
+         "hg export [-a] [-o OUTFILE] REV..."),
     "forget":
         (forget,
          [('I', 'include', [], 'include path in search'),
@@ -1534,7 +1538,7 @@
     "heads":
         (heads,
          [('b', 'branches', None, 'find branch info')],
-         'hg [-b] heads'),
+         'hg heads [-b]'),
     "help": (help_, [], 'hg help [COMMAND]'),
     "identify|id": (identify, [], 'hg identify'),
     "import|patch":
@@ -1542,7 +1546,7 @@
          [('p', 'strip', 1, 'path strip'),
           ('f', 'force', None, 'skip check for outstanding changes'),
           ('b', 'base', "", 'base path')],
-         "hg import [-p NUM] [-b BASE] PATCH..."),
+         "hg import [-f] [-p NUM] [-b BASE] PATCH..."),
     "incoming|in": (incoming, [], 'hg incoming [SOURCE]'),
     "^init": (init, [], 'hg init [DEST]'),
     "locate":
@@ -1559,7 +1563,7 @@
           ('X', 'exclude', [], 'exclude path from search'),
           ('r', 'rev', [], 'revision'),
           ('p', 'patch', None, 'show patch')],
-         'hg log [-r REV1 [-r REV2]] [-p] [FILE]'),
+         'hg log [-I] [-X] [-r REV]... [-p] [FILE]'),
     "manifest": (manifest, [], 'hg manifest [REV]'),
     "outgoing|out": (outgoing, [], 'hg outgoing [DEST]'),
     "parents": (parents, [], 'hg parents [REV]'),
@@ -1569,13 +1573,13 @@
          [('u', 'update', None, 'update working directory'),
           ('e', 'ssh', "", 'ssh command'),
           ('', 'remotecmd', "", 'remote hg command')],
-         'hg pull [OPTIONS] [SOURCE]'),
+         'hg pull [-u] [-e FILE] [--remotecmd FILE] [SOURCE]'),
     "^push":
         (push,
          [('f', 'force', None, 'force push'),
           ('e', 'ssh', "", 'ssh command'),
           ('', 'remotecmd', "", 'remote hg command')],
-         'hg push [-f] [DEST]'),
+         'hg push [-f] [-e FILE] [--remotecmd FILE] [DEST]'),
     "rawcommit":
         (rawcommit,
          [('p', 'parent', [], 'parent'),
@@ -1634,19 +1638,21 @@
          'hg update [-b TAG] [-m] [-C] [REV]'),
     "verify": (verify, [], 'hg verify'),
     "version": (show_version, [], 'hg version'),
-    }
+}
 
-globalopts = [('v', 'verbose', None, 'verbose mode'),
-              ('', 'debug', None, 'debug mode'),
-              ('q', 'quiet', None, 'quiet mode'),
-              ('', 'profile', None, 'profile'),
-              ('', 'cwd', '', 'change working directory'),
-              ('R', 'repository', "", 'repository root directory'),
-              ('', 'traceback', None, 'print traceback on exception'),
-              ('y', 'noninteractive', None, 'run non-interactively'),
-              ('', 'version', None, 'output version information and exit'),
-              ('', 'time', None, 'time how long the command takes'),
-             ]
+globalopts = [
+    ('R', 'repository', "", 'repository root directory'),
+    ('', 'cwd', '', 'change working directory'),
+    ('y', 'noninteractive', None, 'run non-interactively'),
+    ('q', 'quiet', None, 'quiet mode'),
+    ('v', 'verbose', None, 'verbose mode'),
+    ('', 'debug', None, 'debug mode'),
+    ('', 'traceback', None, 'print traceback on exception'),
+    ('', 'time', None, 'time how long the command takes'),
+    ('', 'profile', None, 'profile'),
+    ('', 'version', None, 'output version information and exit'),
+    ('h', 'help', None, 'display help and exit'),
+]
 
 norepo = "clone init version help debugconfig debugdata" + \
          " debugindex debugindexdot paths"
@@ -1679,17 +1685,15 @@
     except fancyopts.getopt.GetoptError, inst:
         raise ParseError(None, inst)
 
-    if options["version"]:
-        return ("version", show_version, [], options, cmdoptions)
-    elif not args:
-        return ("help", help_, ["shortlist"], options, cmdoptions)
+    if args:
+        cmd, args = args[0], args[1:]
+        i = find(cmd)[1]
+        c = list(i[1])
     else:
-        cmd, args = args[0], args[1:]
-
-    i = find(cmd)[1]
+        cmd = None
+        c = []
 
     # combine global options into local
-    c = list(i[1])
     for o in globalopts:
         c.append((o[0], o[1], options[o[1]], o[3]))
 
@@ -1704,7 +1708,7 @@
         options[n] = cmdoptions[n]
         del cmdoptions[n]
 
-    return (cmd, i[0], args, options, cmdoptions)
+    return (cmd, cmd and i[0] or None, args, options, cmdoptions)
 
 def dispatch(args):
     signal.signal(signal.SIGTERM, catchterm)
@@ -1730,14 +1734,6 @@
         help_(u, 'shortlist')
         sys.exit(1)
 
-    if options['cwd']:
-        try:
-            os.chdir(options['cwd'])
-        except OSError, inst:
-            u = ui.ui()
-            u.warn('abort: %s: %s\n' % (options['cwd'], inst.strerror))
-            sys.exit(1)
-
     if options["time"]:
         def get_times():
             t = os.times()
@@ -1757,6 +1753,23 @@
 
     try:
         try:
+            if options['help']:
+                help_(u, cmd, options['version'])
+                sys.exit(0)
+            elif options['version']:
+                show_version(u)
+                sys.exit(0)
+            elif not cmd:
+                help_(u, 'shortlist')
+                sys.exit(0)
+
+            if options['cwd']:
+                try:
+                    os.chdir(options['cwd'])
+                except OSError, inst:
+                    u.warn('abort: %s: %s\n' % (options['cwd'], inst.strerror))
+                    sys.exit(1)
+
             if cmd not in norepo.split():
                 path = options["repository"] or ""
                 repo = hg.repository(ui=u, path=path)
--- a/tests/test-copy.out	Thu Aug 25 17:13:48 2005 -0700
+++ b/tests/test-copy.out	Fri Aug 26 01:56:49 2005 -0700
@@ -20,7 +20,6 @@
 
 
 we should see one log entry for a
-filelog
 changeset:   0:c19d34741b0a
 user:        test
 date:        Thu Jan  1 00:00:00 1970 +0000
@@ -30,7 +29,6 @@
    rev    offset  length   base linkrev nodeid       p1           p2
      0         0       3      0       0 b789fdd96dc2 000000000000 000000000000
 we should see one log entry for b
-filelog
 changeset:   1:3b5b84850bbe
 tag:         tip
 user:        test
--- a/tests/test-help.out	Thu Aug 25 17:13:48 2005 -0700
+++ b/tests/test-help.out	Fri Aug 26 01:56:49 2005 -0700
@@ -46,6 +46,7 @@
  diff        diff working directory (or selected files)
  export      dump the header and diffs for one or more changesets
  forget      don't add the specified files on the next commit
+ grep        search for a pattern in specified files and revisions
  heads       show current repository heads
  help        show help for a given command or all commands
  identify    print information about the working copy
@@ -84,6 +85,7 @@
  diff        diff working directory (or selected files)
  export      dump the header and diffs for one or more changesets
  forget      don't add the specified files on the next commit
+ grep        search for a pattern in specified files and revisions
  heads       show current repository heads
  help        show help for a given command or all commands
  identify    print information about the working copy
@@ -112,17 +114,14 @@
  update      update or merge working directory
  verify      verify the integrity of the repository
  version     output version and copyright information
-hg add: option -h not recognized
 hg add [OPTION]... [FILE]...
 
 add the specified files on the next commit
 
 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]...
 
@@ -130,24 +129,18 @@
 
 options:
 
- -I --include 
-   include path in search
- -X --exclude 
-   exclude path from search
-hg diff [-I] [-X] [-r REV1 [-r REV2]] [FILE]...
+ -I --include  include path in search
+ -X --exclude  exclude path from search
+hg diff [-a] [-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
@@ -159,18 +152,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