# HG changeset patch # User Erik Zielke # Date 1287589509 -7200 # Node ID 0d09991f91ee96a9f996a19961f02771a88e89af # Parent bdc1cf6924479ec4ea43433f1689a8d9465ac3a3 gendoc: automatically create help for default extensions. Adds a section in the hg.1 manpage and corresponding hg.1.html file. Each extension is listed with its module docstring, followed by the commands defined by that extendsion. Creates help for extensions by extracting doc strings from the extension modules and its commands. diff -r bdc1cf692447 -r 0d09991f91ee doc/gendoc.py --- a/doc/gendoc.py Tue Oct 19 13:50:03 2010 +0200 +++ b/doc/gendoc.py Wed Oct 20 17:45:09 2010 +0200 @@ -8,6 +8,7 @@ from mercurial.commands import table, globalopts from mercurial.i18n import _ from mercurial.help import helptable +from mercurial import extensions def get_desc(docstr): if not docstr: @@ -67,6 +68,12 @@ def subsection(ui, s): ui.write("%s\n%s\n\n" % (s, '"' * encoding.colwidth(s))) +def subsubsection(ui, s): + ui.write("%s\n%s\n\n" % (s, "." * encoding.colwidth(s))) + +def subsubsubsection(ui, s): + ui.write("%s\n%s\n\n" % (s, "#" * encoding.colwidth(s))) + def show_doc(ui): # print options @@ -76,7 +83,7 @@ # print cmds section(ui, _("Commands")) - commandprinter(ui, table) + commandprinter(ui, table, subsection) # print topics for names, sec, doc in helptable: @@ -89,7 +96,26 @@ ui.write(doc) ui.write("\n") -def commandprinter(ui, cmdtable): + section(ui, _("Extensions")) + ui.write(_("This section contains help for extensions that is distributed " + "together with Mercurial. Help for other extensions is available " + "in the help system.")) + ui.write("\n\n" + ".. contents::\n" + " :class: htmlonly\n" + " :local:\n" + " :depth: 1\n\n") + + for extensionname in sorted(allextensionnames()): + mod = extensions.load(None, extensionname, None) + subsection(ui, extensionname) + ui.write("%s\n\n" % mod.__doc__) + cmdtable = getattr(mod, 'cmdtable', None) + if cmdtable: + subsubsection(ui, _('Commands')) + commandprinter(ui, cmdtable, subsubsubsection) + +def commandprinter(ui, cmdtable, sectionfunc): h = {} for c, attr in cmdtable.items(): f = c.split("|")[0] @@ -102,7 +128,7 @@ if f.startswith("debug"): continue d = get_cmd(h[f], cmdtable) - subsection(ui, d['cmd']) + sectionfunc(ui, d['cmd']) # synopsis ui.write("``%s``\n" % d['synopsis'].replace("hg ","", 1)) ui.write("\n") @@ -125,5 +151,17 @@ ui.write(_(" aliases: %s\n\n") % " ".join(d['aliases'])) +def allextensionnames(): + extensionnames = [] + + extensionsdictionary = extensions.enabled()[0] + extensionnames.extend(extensionsdictionary.keys()) + + extensionsdictionary = extensions.disabled()[0] + extensionnames.extend(extensionsdictionary.keys()) + + return extensionnames + + if __name__ == "__main__": show_doc(sys.stdout)