help: do not show full help text for command on option errors

Example

  $ hg clone --jump foo bar
  hg clone: option --jump not recognized
  hg clone [OPTION]... SOURCE [DEST]

  make a copy of an existing repository

  options:

   -U --noupdate           the clone will include an empty working copy (only a
                           repository)
   -u --updaterev REV      revision, tag or branch to check out
   -r --rev REV [+]        include the specified changeset
   -b --branch BRANCH [+]  clone only the specified branch
      --pull               use pull protocol to copy metadata
      --uncompressed       use uncompressed transfer (fast over LAN)
   -e --ssh CMD            specify ssh command to use
      --remotecmd CMD      specify hg command to run on the remote side
      --insecure           do not verify server certificate (ignoring
                           web.cacerts config)

  [+] marked option can be specified multiple times

  use "hg help clone" to show the full help text

Motivation for this change

  If the user already has specified the command, he probably already knows
  the command to some extent. Apparently, he has a problem with the options,
  so we show him just the synopsis with the short help and the details about
  the options, with a hint on the last line how to get the full help text.

Why is Mercurial better with this change?

  Experts who just forgot about the details of an option don't get that
  much text thrown at them, while the newbies still get a hint on the last
  line how to get the full help text.
This commit is contained in:
Adrian Buehlmann 2011-04-17 11:37:11 +02:00
parent d3fe813516
commit 3efb31d590
6 changed files with 10 additions and 41 deletions

View File

@ -2047,7 +2047,7 @@ def heads(ui, repo, *branchrevs, **opts):
displayer.show(ctx)
displayer.close()
def help_(ui, name=None, with_version=False, unknowncmd=False):
def help_(ui, name=None, with_version=False, unknowncmd=False, full=True):
"""show help for a given topic or a help overview
With no arguments, print a list of commands with short help messages.
@ -2070,6 +2070,8 @@ def help_(ui, name=None, with_version=False, unknowncmd=False):
if name == 'shortlist':
msg = _('use "hg help" for the full list of commands '
'or "hg -v" for details')
elif name and not full:
msg = _('use "hg help %s" to show the full help text' % name)
elif aliases:
msg = _('use "hg -v help%s" to show builtin aliases and '
'global options') % (name and " " + name or "")
@ -2108,7 +2110,7 @@ def help_(ui, name=None, with_version=False, unknowncmd=False):
ui.write('hg %s\n' % aliases[0])
# aliases
if not ui.quiet and len(aliases) > 1:
if full and not ui.quiet and len(aliases) > 1:
ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:]))
# description
@ -2120,7 +2122,7 @@ def help_(ui, name=None, with_version=False, unknowncmd=False):
doc = _('shell alias for::\n\n %s') % entry[0].definition[1:]
else:
doc = _('alias for: hg %s\n\n%s') % (entry[0].definition, doc)
if ui.quiet:
if ui.quiet or not full:
doc = doc.splitlines()[0]
keep = ui.verbose and ['verbose'] or []
formatted, pruned = minirst.format(doc, textwidth, keep=keep)

View File

@ -90,7 +90,7 @@ def _runcatch(ui, args):
except error.CommandError, inst:
if inst.args[0]:
ui.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1]))
commands.help_(ui, inst.args[0])
commands.help_(ui, inst.args[0], full=False)
else:
ui.warn(_("hg: %s\n") % inst.args[1])
commands.help_(ui, 'shortlist')

View File

@ -304,13 +304,7 @@ invalid arguments
alias for: hg root
print the root (top) of the current working directory
Print the root directory of the current repository.
Returns 0 on success.
use "hg -v help rt" to show global options
use "hg help rt" to show the full help text
[255]
invalid global arguments for normal commands, aliases, and shell aliases

View File

@ -18,20 +18,6 @@ Missing arg:
output the current or given revision of files
Print the specified files as they were at the given revision. If no
revision is given, the parent of the working directory is used, or tip if
no revision is checked out.
Output may be to a file, in which case the name of the file is given using
a format string. The formatting rules are the same as for the export
command, with the following additions:
"%s" basename of file being printed
"%d" dirname of file being printed, or '.' if in repository root
"%p" root-relative path name of file being printed
Returns 0 on success.
options:
-o --output FORMAT print output to file with formatted name
@ -42,7 +28,7 @@ Missing arg:
[+] marked option can be specified multiple times
use "hg -v help cat" to show global options
use "hg help cat" to show the full help text
[255]
[defaults]

View File

@ -387,17 +387,6 @@ Test help option with version option
add the specified files on the next commit
Schedule files to be version controlled and added to the repository.
The files will be added to the repository at the next commit. To undo an
add before that, see "hg forget".
If no names are given, add all files to the repository.
Returns 0 if all files are successfully added.
use "hg -v help add" to show verbose help
options:
-I --include PATTERN [+] include names matching the given patterns
@ -407,7 +396,7 @@ Test help option with version option
[+] marked option can be specified multiple times
use "hg -v help add" to show global options
use "hg help add" to show the full help text
[255]
Test ambiguous command help

View File

@ -90,9 +90,7 @@ qrecord (mq not present)
interactively record a new patch
See "hg help qnew" & "hg help record" for more information and usage.
use "hg -v help qrecord" to show global options
use "hg help qrecord" to show the full help text
[255]
qrecord patch (mq not present)