comparison doc/gendoc.py @ 12756:13f0acfa974a

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.
author Erik Zielke <ez@aragost.com>
date Mon, 18 Oct 2010 14:37:52 +0200
parents 2d88369a27bf
children 4f4eddee254d
comparison
equal deleted inserted replaced
12755:db79d3627872 12756:13f0acfa974a
36 if longopt: 36 if longopt:
37 allopts.append("--%s" % longopt) 37 allopts.append("--%s" % longopt)
38 desc += default and _(" (default: %s)") % default or "" 38 desc += default and _(" (default: %s)") % default or ""
39 yield(", ".join(allopts), desc) 39 yield(", ".join(allopts), desc)
40 40
41 def get_cmd(cmd): 41 def get_cmd(cmd, cmdtable):
42 d = {} 42 d = {}
43 attr = table[cmd] 43 attr = cmdtable[cmd]
44 cmds = cmd.lstrip("^").split("|") 44 cmds = cmd.lstrip("^").split("|")
45 45
46 d['cmd'] = cmds[0] 46 d['cmd'] = cmds[0]
47 d['aliases'] = cmd.split("|")[1:] 47 d['aliases'] = cmd.split("|")[1:]
48 d['desc'] = get_desc(attr[0].__doc__) 48 d['desc'] = get_desc(attr[0].__doc__)
69 for optstr, desc in get_opts(globalopts): 69 for optstr, desc in get_opts(globalopts):
70 ui.write("%s\n %s\n\n" % (optstr, desc)) 70 ui.write("%s\n %s\n\n" % (optstr, desc))
71 71
72 # print cmds 72 # print cmds
73 section(_("Commands")) 73 section(_("Commands"))
74 commandprinter(ui, table)
75
76 # print topics
77 for names, sec, doc in helptable:
78 for name in names:
79 ui.write(".. _%s:\n" % name)
80 ui.write("\n")
81 section(sec)
82 if hasattr(doc, '__call__'):
83 doc = doc()
84 ui.write(doc)
85 ui.write("\n")
86
87 def commandprinter(ui, cmdtable):
74 h = {} 88 h = {}
75 for c, attr in table.items(): 89 for c, attr in cmdtable.items():
76 f = c.split("|")[0] 90 f = c.split("|")[0]
77 f = f.lstrip("^") 91 f = f.lstrip("^")
78 h[f] = c 92 h[f] = c
79 cmds = h.keys() 93 cmds = h.keys()
80 cmds.sort() 94 cmds.sort()
81 95
82 for f in cmds: 96 for f in cmds:
83 if f.startswith("debug"): 97 if f.startswith("debug"):
84 continue 98 continue
85 d = get_cmd(h[f]) 99 d = get_cmd(h[f], cmdtable)
86 # synopsis 100 # synopsis
87 ui.write(".. _%s:\n\n" % d['cmd']) 101 ui.write(".. _%s:\n\n" % d['cmd'])
88 ui.write("``%s``\n" % d['synopsis'].replace("hg ","", 1)) 102 ui.write("``%s``\n" % d['synopsis'].replace("hg ","", 1))
89 # description 103 # description
90 ui.write("%s\n\n" % d['desc'][1]) 104 ui.write("%s\n\n" % d['desc'][1])
102 ui.write("\n") 116 ui.write("\n")
103 # aliases 117 # aliases
104 if d['aliases']: 118 if d['aliases']:
105 ui.write(_(" aliases: %s\n\n") % " ".join(d['aliases'])) 119 ui.write(_(" aliases: %s\n\n") % " ".join(d['aliases']))
106 120
107 # print topics
108 for names, sec, doc in helptable:
109 for name in names:
110 ui.write(".. _%s:\n" % name)
111 ui.write("\n")
112 section(sec)
113 if hasattr(doc, '__call__'):
114 doc = doc()
115 ui.write(doc)
116 ui.write("\n")
117 121
118 if __name__ == "__main__": 122 if __name__ == "__main__":
119 show_doc(sys.stdout) 123 show_doc(sys.stdout)