##// END OF EJS Templates
gendoc: fix indentation
Christian Ebert -
r6488:119dff2c default
parent child Browse files
Show More
@@ -1,105 +1,105 b''
1 import sys, textwrap
1 import sys, textwrap
2 # import from the live mercurial repo
2 # import from the live mercurial repo
3 sys.path.insert(0, "..")
3 sys.path.insert(0, "..")
4 from mercurial import demandimport; demandimport.enable()
4 from mercurial import demandimport; demandimport.enable()
5 from mercurial.commands import table, globalopts
5 from mercurial.commands import table, globalopts
6 from mercurial.i18n import gettext as _
6 from mercurial.i18n import gettext as _
7 from mercurial.help import helptable
7 from mercurial.help import helptable
8
8
9 def get_desc(docstr):
9 def get_desc(docstr):
10 if not docstr:
10 if not docstr:
11 return "", ""
11 return "", ""
12 # sanitize
12 # sanitize
13 docstr = docstr.strip("\n")
13 docstr = docstr.strip("\n")
14 docstr = docstr.rstrip()
14 docstr = docstr.rstrip()
15 shortdesc = docstr.splitlines()[0].strip()
15 shortdesc = docstr.splitlines()[0].strip()
16
16
17 i = docstr.find("\n")
17 i = docstr.find("\n")
18 if i != -1:
18 if i != -1:
19 desc = docstr[i+2:]
19 desc = docstr[i+2:]
20 else:
20 else:
21 desc = " %s" % shortdesc
21 desc = " %s" % shortdesc
22 return (shortdesc, desc)
22 return (shortdesc, desc)
23
23
24 def get_opts(opts):
24 def get_opts(opts):
25 for shortopt, longopt, default, desc in opts:
25 for shortopt, longopt, default, desc in opts:
26 allopts = []
26 allopts = []
27 if shortopt:
27 if shortopt:
28 allopts.append("-%s" % shortopt)
28 allopts.append("-%s" % shortopt)
29 if longopt:
29 if longopt:
30 allopts.append("--%s" % longopt)
30 allopts.append("--%s" % longopt)
31 desc += default and _(" (default: %s)") % default or ""
31 desc += default and _(" (default: %s)") % default or ""
32 yield(", ".join(allopts), desc)
32 yield(", ".join(allopts), desc)
33
33
34 def get_cmd(cmd):
34 def get_cmd(cmd):
35 d = {}
35 d = {}
36 attr = table[cmd]
36 attr = table[cmd]
37 cmds = cmd.lstrip("^").split("|")
37 cmds = cmd.lstrip("^").split("|")
38
38
39 d['synopsis'] = attr[2]
39 d['synopsis'] = attr[2]
40 d['cmd'] = cmds[0]
40 d['cmd'] = cmds[0]
41 d['aliases'] = cmd.split("|")[1:]
41 d['aliases'] = cmd.split("|")[1:]
42 d['desc'] = get_desc(attr[0].__doc__)
42 d['desc'] = get_desc(attr[0].__doc__)
43 d['opts'] = list(get_opts(attr[1]))
43 d['opts'] = list(get_opts(attr[1]))
44 return d
44 return d
45
45
46
46
47 def show_doc(ui):
47 def show_doc(ui):
48 def bold(s, text=""):
48 def bold(s, text=""):
49 ui.write("%s\n%s\n%s\n" % (s, "="*len(s), text))
49 ui.write("%s\n%s\n%s\n" % (s, "="*len(s), text))
50 def underlined(s, text=""):
50 def underlined(s, text=""):
51 ui.write("%s\n%s\n%s\n" % (s, "-"*len(s), text))
51 ui.write("%s\n%s\n%s\n" % (s, "-"*len(s), text))
52
52
53 # print options
53 # print options
54 underlined(_("OPTIONS"))
54 underlined(_("OPTIONS"))
55 for optstr, desc in get_opts(globalopts):
55 for optstr, desc in get_opts(globalopts):
56 ui.write("%s::\n %s\n\n" % (optstr, desc))
56 ui.write("%s::\n %s\n\n" % (optstr, desc))
57
57
58 # print cmds
58 # print cmds
59 underlined(_("COMMANDS"))
59 underlined(_("COMMANDS"))
60 h = {}
60 h = {}
61 for c, attr in table.items():
61 for c, attr in table.items():
62 f = c.split("|")[0]
62 f = c.split("|")[0]
63 f = f.lstrip("^")
63 f = f.lstrip("^")
64 h[f] = c
64 h[f] = c
65 cmds = h.keys()
65 cmds = h.keys()
66 cmds.sort()
66 cmds.sort()
67
67
68 for f in cmds:
68 for f in cmds:
69 if f.startswith("debug"): continue
69 if f.startswith("debug"): continue
70 d = get_cmd(h[f])
70 d = get_cmd(h[f])
71 # synopsis
71 # synopsis
72 ui.write("%s::\n" % d['synopsis'].replace("hg ","", 1))
72 ui.write("%s::\n" % d['synopsis'].replace("hg ","", 1))
73 # description
73 # description
74 ui.write("%s\n\n" % d['desc'][1])
74 ui.write("%s\n\n" % d['desc'][1])
75 # options
75 # options
76 opt_output = list(d['opts'])
76 opt_output = list(d['opts'])
77 if opt_output:
77 if opt_output:
78 opts_len = max([len(line[0]) for line in opt_output])
78 opts_len = max([len(line[0]) for line in opt_output])
79 ui.write(_(" options:\n"))
79 ui.write(_(" options:\n"))
80 for optstr, desc in opt_output:
80 for optstr, desc in opt_output:
81 if desc:
81 if desc:
82 s = "%-*s %s" % (opts_len, optstr, desc)
82 s = "%-*s %s" % (opts_len, optstr, desc)
83 else:
83 else:
84 s = optstr
84 s = optstr
85 s = textwrap.fill(s, initial_indent=4 * " ",
85 s = textwrap.fill(s, initial_indent=4 * " ",
86 subsequent_indent=(6 + opts_len) * " ")
86 subsequent_indent=(6 + opts_len) * " ")
87 ui.write("%s\n" % s)
87 ui.write("%s\n" % s)
88 ui.write("\n")
88 ui.write("\n")
89 # aliases
89 # aliases
90 if d['aliases']:
90 if d['aliases']:
91 ui.write(_(" aliases: %s\n\n") % " ".join(d['aliases']))
91 ui.write(_(" aliases: %s\n\n") % " ".join(d['aliases']))
92
92
93 # print topics
93 # print topics
94 for t in helptable:
94 for t in helptable:
95 l = t.split("|")
95 l = t.split("|")
96 section = l[-1]
96 section = l[-1]
97 underlined(_(section).upper())
97 underlined(_(section).upper())
98 doc = helptable[t]
98 doc = helptable[t]
99 if callable(doc):
99 if callable(doc):
100 doc = doc()
100 doc = doc()
101 ui.write(_(doc))
101 ui.write(_(doc))
102 ui.write("\n")
102 ui.write("\n")
103
103
104 if __name__ == "__main__":
104 if __name__ == "__main__":
105 show_doc(sys.stdout)
105 show_doc(sys.stdout)
General Comments 0
You need to be logged in to leave comments. Login now