[PATCH 06 of 10] help: generate and use option list rst for commands
Erik Zielke
ez at aragost.com
Wed Nov 17 11:11:05 CST 2010
# HG changeset patch
# User Erik Zielke <ez at aragost.com>
# Date 1289297720 -3600
# Node ID 7162beaa1465404a34593d1b647881229f7e947f
# Parent c348babb414630ad11408c4106e1af3e1c9a6f39
help: generate and use option list rst for commands
diff -r c348babb4146 -r 7162beaa1465 mercurial/commands.py
--- a/mercurial/commands.py Tue Nov 09 09:47:56 2010 +0100
+++ b/mercurial/commands.py Tue Nov 09 11:15:20 2010 +0100
@@ -1869,28 +1869,10 @@
Returns 0 if successful.
"""
- option_lists = []
textwidth = ui.termwidth() - 2
helpconfig = help.createhelpconfig(name, ui.verbose, ui.quiet, True,
table, ui.debugflag, globalopts)
- 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:
versionrst = help.generateversionrst(ui.quiet)
@@ -1946,10 +1928,25 @@
if not ui.quiet:
# options
+ optionlists = []
if entry[1]:
- option_lists.append((_("options:\n"), entry[1]))
-
- addglobalopts(False)
+ cmds, h = help.cleancmdsmap(table)
+ d = help.getcmd(h[name], table, helpconfig)
+ optionlists.append((_("options:"), d['opts']))
+
+ if helpconfig['verbose']:
+ optionlists.append((_("global options:"),
+ list(help.getopts(helpconfig['globalopts'], helpconfig))))
+
+ optlistrst = help.generateoptionslistsrst(optionlists,
+ helpconfig['name'],
+ helpconfig['verbose'],
+ helpconfig['cmdline'],
+ helpconfig['quiet'], False, False)
+ formatted = minirst.format(optlistrst, textwidth)
+ ui.write('\n')
+ ui.write(formatted)
+ ui.write('\n')
def helplist(header, extrainfo, select=None):
helpconfig['extrainfo'] = extrainfo
@@ -2045,58 +2042,6 @@
helplist(header, True)
- # list all option lists
- opt_output = []
- multioccur = False
- for title, options in option_lists:
- opt_output.append(("\n%s" % title, None))
- for option in options:
- if len(option) == 5:
- shortopt, longopt, default, desc, optlabel = option
- else:
- shortopt, longopt, default, desc = option
- optlabel = _("VALUE") # default label
-
- if _("DEPRECATED") in desc and not ui.verbose:
- continue
- if isinstance(default, list):
- numqualifier = " %s [+]" % optlabel
- multioccur = True
- elif (default is not None) and not isinstance(default, bool):
- numqualifier = " %s" % optlabel
- else:
- numqualifier = ""
- opt_output.append(("%2s%s" %
- (shortopt and "-%s" % shortopt,
- longopt and " --%s%s" %
- (longopt, numqualifier)),
- "%s%s" % (desc,
- default
- and _(" (default: %s)") % default
- or "")))
- if multioccur:
- msg = _("\n[+] marked option can be specified multiple times")
- if ui.verbose and name != 'shortlist':
- opt_output.append((msg, None))
- else:
- opt_output.insert(-1, (msg, None))
-
- if opt_output:
- colwidth = encoding.colwidth
- # normalize: (opt or message, desc or None, width of opt)
- entries = [desc and (opt, desc, colwidth(opt)) or (opt, None, 0)
- for opt, desc in opt_output]
- hanging = max([e[2] for e in entries])
- for opt, desc, width in entries:
- if desc:
- initindent = ' %s%s ' % (opt, ' ' * (hanging - width))
- hangindent = ' ' * (hanging + 3)
- ui.write('%s\n' % (util.wrap(desc, textwidth,
- initindent=initindent,
- hangindent=hangindent)))
- else:
- ui.write("%s\n" % opt)
-
def identify(ui, repo, source=None,
rev=None, num=None, id=None, branch=None, tags=None):
"""identify the working copy or specified revision
diff -r c348babb4146 -r 7162beaa1465 tests/test-help.t
--- a/tests/test-help.t Tue Nov 09 09:47:56 2010 +0100
+++ b/tests/test-help.t Tue Nov 09 11:15:20 2010 +0100
@@ -340,24 +340,23 @@
-n --dry-run do not perform actions, just print output
global options:
- -R --repository REPO repository root directory or name of overlay bundle
- file
- --cwd DIR change working directory
- -y --noninteractive do not prompt, assume 'yes' for any required
- answers
- -q --quiet suppress output
- -v --verbose enable additional output
- --config CONFIG [+] set/override config option (use
- 'section.name=value')
- --debug enable debugging output
- --debugger start debugger
- --encoding ENCODE set the charset encoding (default: ascii)
- --encodingmode MODE set the charset encoding mode (default: strict)
- --traceback always print a traceback on exception
- --time time how long the command takes
- --profile print command execution profile
- --version output version information and exit
- -h --help display help and exit
+
+ -R --repository REPO repository root directory or name of overlay bundle
+ file
+ --cwd DIR change working directory
+ -y --noninteractive do not prompt, assume 'yes' for any required answers
+ -q --quiet suppress output
+ -v --verbose enable additional output
+ --config CONFIG [+] set/override config option (use 'section.name=value')
+ --debug enable debugging output
+ --debugger start debugger
+ --encoding ENCODE set the charset encoding (default: ascii)
+ --encodingmode MODE set the charset encoding mode (default: strict)
+ --traceback always print a traceback on exception
+ --time time how long the command takes
+ --profile print command execution profile
+ --version output version information and exit
+ -h --help display help and exit
[+] marked option can be specified multiple times
More information about the Mercurial-devel
mailing list