Mercurial > hg
changeset 16781:c0b98f436cce
help: move some helper functions to help.py
author | Olav Reinert <seroton10@gmail.com> |
---|---|
date | Tue, 22 May 2012 22:08:41 +0200 |
parents | d064da05590d |
children | ba512212dab1 |
files | mercurial/commands.py mercurial/help.py |
diffstat | 2 files changed, 54 insertions(+), 54 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Tue May 22 22:08:41 2012 +0200 +++ b/mercurial/commands.py Tue May 22 22:08:41 2012 +0200 @@ -3089,56 +3089,6 @@ textwidth = min(ui.termwidth(), 80) - 2 - def optrst(options, verbose): - data = [] - multioccur = False - 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 verbose: - continue - - so = '' - if shortopt: - so = '-' + shortopt - lo = '--' + longopt - if default: - desc += _(" (default: %s)") % default - - if isinstance(default, list): - lo += " %s [+]" % optlabel - multioccur = True - elif (default is not None) and not isinstance(default, bool): - lo += " %s" % optlabel - - data.append((so, lo, desc)) - - rst = minirst.maketable(data, 1) - - if multioccur: - rst += _("\n[+] marked option can be specified multiple times\n") - - return rst - - # list all option lists - def opttext(optlist, width, verbose): - rst = '' - if not optlist: - return '' - - for title, options in optlist: - rst += '\n%s\n' % title - if options: - rst += "\n" - rst += optrst(options, verbose) - rst += '\n' - - return '\n' + minirst.format(rst, width) - def addglobalopts(optlist, aliases): if ui.quiet: return [] @@ -3223,13 +3173,13 @@ rst += '\n' rst += _("options:") rst += '\n\n' - rst += optrst(entry[1], ui.verbose) + rst += help.optrst(entry[1], ui.verbose) if ui.verbose: rst += '\n' rst += _("global options:") rst += '\n\n' - rst += optrst(globalopts, ui.verbose) + rst += help.optrst(globalopts, ui.verbose) keep = ui.verbose and ['verbose'] or [] formatted, pruned = minirst.format(rst, textwidth, keep=keep) @@ -3304,7 +3254,7 @@ optlist = [] addglobalopts(optlist, True) - ui.write(opttext(optlist, textwidth, ui.verbose)) + ui.write(help.opttext(optlist, textwidth, ui.verbose)) def helptopic(name): for names, header, doc in help.helptable:
--- a/mercurial/help.py Tue May 22 22:08:41 2012 +0200 +++ b/mercurial/help.py Tue May 22 22:08:41 2012 +0200 @@ -8,7 +8,7 @@ from i18n import gettext, _ import itertools, sys, os import extensions, revset, fileset, templatekw, templatefilters, filemerge -import encoding, util +import encoding, util, minirst def listexts(header, exts, indent=1): '''return a text listing of the given extensions''' @@ -27,6 +27,56 @@ doc += listexts(_('disabled extensions:'), extensions.disabled()) return doc +def optrst(options, verbose): + data = [] + multioccur = False + 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 verbose: + continue + + so = '' + if shortopt: + so = '-' + shortopt + lo = '--' + longopt + if default: + desc += _(" (default: %s)") % default + + if isinstance(default, list): + lo += " %s [+]" % optlabel + multioccur = True + elif (default is not None) and not isinstance(default, bool): + lo += " %s" % optlabel + + data.append((so, lo, desc)) + + rst = minirst.maketable(data, 1) + + if multioccur: + rst += _("\n[+] marked option can be specified multiple times\n") + + return rst + +# list all option lists +def opttext(optlist, width, verbose): + rst = '' + if not optlist: + return '' + + for title, options in optlist: + rst += '\n%s\n' % title + if options: + rst += "\n" + rst += optrst(options, verbose) + rst += '\n' + + return '\n' + minirst.format(rst, width) + def topicmatch(kw): """Return help topics matching kw.