# HG changeset patch # User Erik Zielke # Date 1287405472 -7200 # Node ID 13f0acfa974a1bb4d3f3190a107ea0539edcbbdd # Parent db79d36278721201249fb3af8f1d7baf40b9e398 gendoc: refactor get_cmd Refactors the get_cmd to take the table as argument, instad of just referencing the global table, thereby enabling reuse for extension command tables. diff -r db79d3627872 -r 13f0acfa974a doc/gendoc.py --- a/doc/gendoc.py Mon Oct 18 14:37:50 2010 +0200 +++ b/doc/gendoc.py Mon Oct 18 14:37:52 2010 +0200 @@ -38,9 +38,9 @@ desc += default and _(" (default: %s)") % default or "" yield(", ".join(allopts), desc) -def get_cmd(cmd): +def get_cmd(cmd, cmdtable): d = {} - attr = table[cmd] + attr = cmdtable[cmd] cmds = cmd.lstrip("^").split("|") d['cmd'] = cmds[0] @@ -71,8 +71,22 @@ # print cmds section(_("Commands")) + commandprinter(ui, table) + + # print topics + for names, sec, doc in helptable: + for name in names: + ui.write(".. _%s:\n" % name) + ui.write("\n") + section(sec) + if hasattr(doc, '__call__'): + doc = doc() + ui.write(doc) + ui.write("\n") + +def commandprinter(ui, cmdtable): h = {} - for c, attr in table.items(): + for c, attr in cmdtable.items(): f = c.split("|")[0] f = f.lstrip("^") h[f] = c @@ -82,7 +96,7 @@ for f in cmds: if f.startswith("debug"): continue - d = get_cmd(h[f]) + d = get_cmd(h[f], cmdtable) # synopsis ui.write(".. _%s:\n\n" % d['cmd']) ui.write("``%s``\n" % d['synopsis'].replace("hg ","", 1)) @@ -104,16 +118,6 @@ if d['aliases']: ui.write(_(" aliases: %s\n\n") % " ".join(d['aliases'])) - # print topics - for names, sec, doc in helptable: - for name in names: - ui.write(".. _%s:\n" % name) - ui.write("\n") - section(sec) - if hasattr(doc, '__call__'): - doc = doc() - ui.write(doc) - ui.write("\n") if __name__ == "__main__": show_doc(sys.stdout)