comparison doc/gendoc.py @ 19233:81d9a7f6f2e7

gendoc: extract print help topics into a dedicated function This will be used in an upcoming patch.
author Takumi IINO <trot.thunder@gmail.com>
date Wed, 15 May 2013 15:44:59 +0900
parents 814291b5e79c
children ff1586a3adc5
comparison
equal deleted inserted replaced
19231:814291b5e79c 19233:81d9a7f6f2e7
72 72
73 # print cmds 73 # print cmds
74 ui.write(minirst.section(_("Commands"))) 74 ui.write(minirst.section(_("Commands")))
75 commandprinter(ui, table, minirst.subsection) 75 commandprinter(ui, table, minirst.subsection)
76 76
77 # print topics 77 # print help topics
78 for names, sec, doc in helptable: 78 # The config help topic is included in the hgrc.5 man page.
79 if names[0] == "config": 79 helpprinter(ui, helptable, minirst.section, exclude=['config'])
80 # The config help topic is included in the hgrc.5 man
81 # page.
82 continue
83 for name in names:
84 ui.write(".. _%s:\n" % name)
85 ui.write("\n")
86 ui.write(minirst.section(sec))
87 if util.safehasattr(doc, '__call__'):
88 doc = doc()
89 ui.write(doc)
90 ui.write("\n")
91 80
92 ui.write(minirst.section(_("Extensions"))) 81 ui.write(minirst.section(_("Extensions")))
93 ui.write(_("This section contains help for extensions that are " 82 ui.write(_("This section contains help for extensions that are "
94 "distributed together with Mercurial. Help for other " 83 "distributed together with Mercurial. Help for other "
95 "extensions is available in the help system.")) 84 "extensions is available in the help system."))
105 ui.write("%s\n\n" % gettext(mod.__doc__)) 94 ui.write("%s\n\n" % gettext(mod.__doc__))
106 cmdtable = getattr(mod, 'cmdtable', None) 95 cmdtable = getattr(mod, 'cmdtable', None)
107 if cmdtable: 96 if cmdtable:
108 ui.write(minirst.subsubsection(_('Commands'))) 97 ui.write(minirst.subsubsection(_('Commands')))
109 commandprinter(ui, cmdtable, minirst.subsubsubsection) 98 commandprinter(ui, cmdtable, minirst.subsubsubsection)
99
100 def helpprinter(ui, helptable, sectionfunc, include=[], exclude=[]):
101 for names, sec, doc in helptable:
102 if exclude and names[0] in exclude:
103 continue
104 if include and names[0] not in include:
105 continue
106 for name in names:
107 ui.write(".. _%s:\n" % name)
108 ui.write("\n")
109 if sectionfunc:
110 ui.write(sectionfunc(sec))
111 if util.safehasattr(doc, '__call__'):
112 doc = doc()
113 ui.write(doc)
114 ui.write("\n")
110 115
111 def commandprinter(ui, cmdtable, sectionfunc): 116 def commandprinter(ui, cmdtable, sectionfunc):
112 h = {} 117 h = {}
113 for c, attr in cmdtable.items(): 118 for c, attr in cmdtable.items():
114 f = c.split("|")[0] 119 f = c.split("|")[0]