Mercurial > hg-stable
changeset 8864:cad6370a15cb
help: refactor extensions listing, and show enabled ones in the dedicated topic
author | Cédric Duval <cedricduval@free.fr> |
---|---|
date | Sat, 20 Jun 2009 20:55:49 +0200 |
parents | 7b19c3c0172b |
children | 37d8a5ddd499 |
files | mercurial/commands.py mercurial/help.py |
diffstat | 2 files changed, 35 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Sat Jun 20 20:55:43 2009 +0200 +++ b/mercurial/commands.py Sat Jun 20 20:55:49 2009 +0200 @@ -1483,18 +1483,10 @@ 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)
--- a/mercurial/help.py Sat Jun 20 20:55:43 2009 +0200 +++ b/mercurial/help.py Sat Jun 20 20:55:49 2009 +0200 @@ -98,6 +98,33 @@ 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 @@ 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