# HG changeset patch # User Cédric Duval # Date 2009-06-20 18:55:49 # Node ID cad6370a15cb2ef6cf28cc509acb58307e6545fb # Parent 7b19c3c0172bc1e0015573182be9551750eda56a help: refactor extensions listing, and show enabled ones in the dedicated topic diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -1483,18 +1483,10 @@ def help_(ui, name=None, with_version=Fa else: ui.write(' %-*s %s\n' % (m, f, h[f])) - exts = list(extensions.extensions()) - if exts and name != 'shortlist': - ui.write(_('\nenabled extensions:\n\n')) - maxlength = 0 - exthelps = [] - for ename, ext in exts: - doc = (gettext(ext.__doc__) or _('(no help text available)')) - ename = ename.split('.')[-1] - maxlength = max(len(ename), maxlength) - exthelps.append((ename, doc.splitlines(0)[0].strip())) - for ename, text in exthelps: - ui.write(_(' %s %s\n') % (ename.ljust(maxlength), text)) + if name != 'shortlist': + exts, maxlength = help.enabledextensions() + ui.write(help.extensionslisting(_('enabled extensions:'), + exts, maxlength)) if not ui.quiet: addglobalopts(True) diff --git a/mercurial/help.py b/mercurial/help.py --- a/mercurial/help.py +++ b/mercurial/help.py @@ -98,6 +98,33 @@ def additionalextensions(): return exts, maxlength +def enabledextensions(): + '''Return the list of enabled extensions, and max name length''' + enabled = list(extensions.extensions()) + exts = {} + maxlength = 0 + + if enabled: + exthelps = [] + for ename, ext in enabled: + doc = (gettext(ext.__doc__) or _('(no help text available)')) + ename = ename.split('.')[-1] + maxlength = max(len(ename), maxlength) + exts[ename] = doc.splitlines(0)[0].strip() + + return exts, maxlength + +def extensionslisting(header, exts, maxlength): + '''Return a text listing of the given extensions''' + result = '' + + if exts: + result += '\n%s\n\n' % header + for name, desc in sorted(exts.iteritems()): + result += ' %s %s\n' % (name.ljust(maxlength), desc) + + return result + def topicextensions(): doc = _(r''' Mercurial has an extension mechanism for adding new features. @@ -109,11 +136,11 @@ def topicextensions(): foo = ''') + exts, maxlength = enabledextensions() + doc += extensionslisting(_('enabled extensions:'), exts, maxlength) + exts, maxlength = additionalextensions() - if exts: - doc += _('\nnon-enabled extensions:\n\n') - for name, desc in sorted(exts.iteritems()): - doc += ' %s %s\n' % (name.ljust(maxlength), desc) + doc += extensionslisting(_('non-enabled extensions:'), exts, maxlength) return doc