# HG changeset patch # User Olav Reinert # Date 2012-06-02 09:22:33 # Node ID af69b2b64d6ed0dfc9f2e40bf606ba08a0d2cb61 # Parent c739227b5eead90a73a40b39d7de13e82dceb394 help: format extension lists using RST This change is a move towards generating all help text as a list of strings marked up with RST. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -3218,9 +3218,9 @@ def help_(ui, name=None, unknowncmd=Fals hangindent=' ' * (m + 4)))) if not name: - text = help.listexts(_('enabled extensions:'), extensions.enabled()) - if text: - ui.write("\n%s" % minirst.format(text, textwidth)) + rst = help.listexts(_('enabled extensions:'), extensions.enabled()) + if rst: + ui.write("\n%s" % minirst.format('\n'.join(rst), textwidth)) ui.write(_("\nadditional help topics:\n\n")) topics = [] @@ -3318,12 +3318,12 @@ def help_(ui, name=None, unknowncmd=Fals ui.configbool('ui', 'strict')) doc = gettext(mod.__doc__).splitlines()[0] - msg = help.listexts(_("'%s' is provided by the following " + rst = help.listexts(_("'%s' is provided by the following " "extension:") % cmd, {ext: doc}, indent=4) - ui.write(minirst.format(msg, textwidth)) - ui.write('\n') - ui.write(_('use "hg help extensions" for information on enabling ' + rst.append('\n') + rst.append(_('use "hg help extensions" for information on enabling ' 'extensions\n')) + ui.write(minirst.format(''.join(rst), textwidth)) kw = opts.get('keyword') if kw: diff --git a/mercurial/help.py b/mercurial/help.py --- a/mercurial/help.py +++ b/mercurial/help.py @@ -12,19 +12,18 @@ import encoding, util, minirst def listexts(header, exts, indent=1): '''return a text listing of the given extensions''' - if not exts: - return '' - maxlength = max(len(e) for e in exts) - result = '\n%s\n\n' % header - for name, desc in sorted(exts.iteritems()): - result += '%s%-*s %s\n' % (' ' * indent, maxlength + 2, - ':%s:' % name, desc) - return result + rst = [] + if exts: + rst.append('\n%s\n\n' % header) + for name, desc in sorted(exts.iteritems()): + rst.append('%s:%s: %s\n' % (' ' * indent, name, desc)) + return rst def extshelp(): - doc = loaddoc('extensions')() - doc += listexts(_('enabled extensions:'), extensions.enabled()) - doc += listexts(_('disabled extensions:'), extensions.disabled()) + rst = loaddoc('extensions')().splitlines(True) + rst.extend(listexts(_('enabled extensions:'), extensions.enabled())) + rst.extend(listexts(_('disabled extensions:'), extensions.disabled())) + doc = ''.join(rst) return doc def optrst(options, verbose):