##// END OF EJS Templates
Generate docs for help topics
Matt Mackall -
r3797:54fd4d3b default
parent child Browse files
Show More
@@ -1,92 +1,104 b''
1 1 import sys, textwrap
2 2 # import from the live mercurial repo
3 3 sys.path.insert(0, "..")
4 4 from mercurial.commands import table, globalopts
5 5 from mercurial.i18n import gettext as _
6 from mercurial.help import helptable
6 7
7 8 def get_desc(docstr):
8 9 if not docstr:
9 10 return "", ""
10 11 # sanitize
11 12 docstr = docstr.strip("\n")
12 13 docstr = docstr.rstrip()
13 14 shortdesc = docstr.splitlines()[0].strip()
14 15
15 16 i = docstr.find("\n")
16 17 if i != -1:
17 18 desc = docstr[i+2:]
18 19 else:
19 20 desc = " %s" % shortdesc
20 21 return (shortdesc, desc)
21 22
22 23 def get_opts(opts):
23 24 for shortopt, longopt, default, desc in opts:
24 25 allopts = []
25 26 if shortopt:
26 27 allopts.append("-%s" % shortopt)
27 28 if longopt:
28 29 allopts.append("--%s" % longopt)
29 30 desc += default and _(" (default: %s)") % default or ""
30 31 yield(", ".join(allopts), desc)
31 32
32 33 def get_cmd(cmd):
33 34 d = {}
34 35 attr = table[cmd]
35 36 cmds = cmd.lstrip("^").split("|")
36 37
37 38 d['synopsis'] = attr[2]
38 39 d['cmd'] = cmds[0]
39 40 d['aliases'] = cmd.split("|")[1:]
40 41 d['desc'] = get_desc(attr[0].__doc__)
41 42 d['opts'] = list(get_opts(attr[1]))
42 43 return d
43 44
44 45
45 46 def show_doc(ui):
46 47 def bold(s, text=""):
47 48 ui.write("%s\n%s\n%s\n" % (s, "="*len(s), text))
48 49 def underlined(s, text=""):
49 50 ui.write("%s\n%s\n%s\n" % (s, "-"*len(s), text))
50 51
51 52 # print options
52 53 underlined(_("OPTIONS"))
53 54 for optstr, desc in get_opts(globalopts):
54 55 ui.write("%s::\n %s\n\n" % (optstr, desc))
55 56
56 57 # print cmds
57 58 underlined(_("COMMANDS"))
58 59 h = {}
59 60 for c, attr in table.items():
60 61 f = c.split("|")[0]
61 62 f = f.lstrip("^")
62 63 h[f] = c
63 64 cmds = h.keys()
64 65 cmds.sort()
65 66
66 67 for f in cmds:
67 68 if f.startswith("debug"): continue
68 69 d = get_cmd(h[f])
69 70 # synopsis
70 71 ui.write("%s::\n" % d['synopsis'].replace("hg ","", 1))
71 72 # description
72 73 ui.write("%s\n\n" % d['desc'][1])
73 74 # options
74 75 opt_output = list(d['opts'])
75 76 if opt_output:
76 77 opts_len = max([len(line[0]) for line in opt_output])
77 78 ui.write(_(" options:\n"))
78 79 for optstr, desc in opt_output:
79 80 if desc:
80 81 s = "%-*s %s" % (opts_len, optstr, desc)
81 82 else:
82 83 s = optstr
83 84 s = textwrap.fill(s, initial_indent=4 * " ",
84 85 subsequent_indent=(6 + opts_len) * " ")
85 86 ui.write("%s\n" % s)
86 87 ui.write("\n")
87 88 # aliases
88 89 if d['aliases']:
89 90 ui.write(_(" aliases: %s\n\n") % " ".join(d['aliases']))
90 91
92 # print topics
93 for t in helptable:
94 l = t.split("|")
95 section = l[-1]
96 underlined(_(section).upper())
97 doc = helptable[t]
98 if callable(doc):
99 doc = doc()
100 ui.write(_(doc))
101 ui.write("\n")
102
91 103 if __name__ == "__main__":
92 104 show_doc(sys.stdout)
@@ -1,275 +1,239 b''
1 1 HG(1)
2 2 =====
3 3 Matt Mackall <mpm@selenic.com>
4 4
5 5 NAME
6 6 ----
7 7 hg - Mercurial source code management system
8 8
9 9 SYNOPSIS
10 10 --------
11 11 'hg' [global option]... <command> [command/global option]... [argument]...
12 12
13 13 DESCRIPTION
14 14 -----------
15 15 The hg(1) command provides a command line interface to the Mercurial system.
16 16
17 17 COMMAND ELEMENTS
18 18 ----------------
19 19
20 20 files ...::
21 21 indicates one or more filename or relative path filenames; see
22 22 "FILE NAME PATTERNS" for information on pattern matching
23 23
24 24 path::
25 25 indicates a path on the local machine
26 26
27 27 revision::
28 28 indicates a changeset which can be specified as a changeset revision
29 29 number, a tag, or a unique substring of the changeset hash value
30 30
31 31 repository path::
32 32 either the pathname of a local repository or the URI of a remote
33 33 repository. There are two available URI protocols, http:// which is
34 34 fast and the static-http:// protocol which is much slower but does not
35 35 require a special server on the web host.
36 36
37 37
38 38 include::hg.1.gendoc.txt[]
39 39
40 40 FILE NAME PATTERNS
41 41 ------------------
42 42
43 43 Mercurial accepts several notations for identifying one or more
44 44 files at a time.
45 45
46 46 By default, Mercurial treats filenames as shell-style extended
47 47 glob patterns.
48 48
49 49 Alternate pattern notations must be specified explicitly.
50 50
51 51 To use a plain path name without any pattern matching, start a
52 52 name with "path:". These path names must match completely, from
53 53 the root of the current repository.
54 54
55 55 To use an extended glob, start a name with "glob:". Globs are
56 56 rooted at the current directory; a glob such as "*.c" will match
57 57 files ending in ".c" in the current directory only.
58 58
59 59 The supported glob syntax extensions are "**" to match any string
60 60 across path separators, and "{a,b}" to mean "a or b".
61 61
62 62 To use a Perl/Python regular expression, start a name with "re:".
63 63 Regexp pattern matching is anchored at the root of the repository.
64 64
65 65 Plain examples:
66 66
67 67 path:foo/bar a name bar in a directory named foo in the root of
68 68 the repository
69 69 path:path:name a file or directory named "path:name"
70 70
71 71 Glob examples:
72 72
73 73 glob:*.c any name ending in ".c" in the current directory
74 74 *.c any name ending in ".c" in the current directory
75 75 **.c any name ending in ".c" in the current directory, or
76 76 any subdirectory
77 77 foo/*.c any name ending in ".c" in the directory foo
78 78 foo/**.c any name ending in ".c" in the directory foo, or any
79 79 subdirectory
80 80
81 81 Regexp examples:
82 82
83 83 re:.*\.c$ any name ending in ".c", anywhere in the repository
84 84
85 85
86 86 SPECIFYING SINGLE REVISIONS
87 87 ---------------------------
88 88
89 89 Mercurial accepts several notations for identifying individual
90 90 revisions.
91 91
92 92 A plain integer is treated as a revision number. Negative
93 93 integers are treated as offsets from the tip, with -1 denoting the
94 94 tip.
95 95
96 96 A 40-digit hexadecimal string is treated as a unique revision
97 97 identifier.
98 98
99 99 A hexadecimal string less than 40 characters long is treated as a
100 100 unique revision identifier, and referred to as a short-form
101 101 identifier. A short-form identifier is only valid if it is the
102 102 prefix of one full-length identifier.
103 103
104 104 Any other string is treated as a tag name, which is a symbolic
105 105 name associated with a revision identifier. Tag names may not
106 106 contain the ":" character.
107 107
108 108 The reserved name "tip" is a special tag that always identifies
109 109 the most recent revision.
110 110
111 111 SPECIFYING MULTIPLE REVISIONS
112 112 -----------------------------
113 113
114 114 When Mercurial accepts more than one revision, they may be
115 115 specified individually, or provided as a continuous range,
116 116 separated by the ":" character.
117 117
118 118 The syntax of range notation is [BEGIN]:[END], where BEGIN and END
119 119 are revision identifiers. Both BEGIN and END are optional. If
120 120 BEGIN is not specified, it defaults to revision number 0. If END
121 121 is not specified, it defaults to the tip. The range ":" thus
122 122 means "all revisions".
123 123
124 124 If BEGIN is greater than END, revisions are treated in reverse
125 125 order.
126 126
127 127 A range acts as a closed interval. This means that a range of 3:5
128 128 gives 3, 4 and 5. Similarly, a range of 4:2 gives 4, 3, and 2.
129 129
130 DATE FORMATS
131 ------------
132
133 Some commands (backout, commit, tag) allow the user to specify a date.
134 Possible formats for dates are:
135
136 YYYY-mm-dd \HH:MM[:SS] [(+|-)NNNN]::
137 This is a subset of ISO 8601, allowing just the recommended notations
138 for date and time. The last part represents the timezone; if omitted,
139 local time is assumed. Examples:
140
141 "2005-08-22 03:27 -0700"
142
143 "2006-04-19 21:39:51"
144
145 aaa bbb dd HH:MM:SS YYYY [(+|-)NNNN]::
146 This is the date format used by the C library. Here, aaa stands for
147 abbreviated weekday name and bbb for abbreviated month name. The last
148 part represents the timezone; if omitted, local time is assumed.
149 Examples:
150
151 "Mon Aug 22 03:27:00 2005 -0700"
152
153 "Wed Apr 19 21:39:51 2006"
154
155 unixtime offset::
156 This is the internal representation format for dates. unixtime is
157 the number of seconds since the epoch (1970-01-01 00:00 UTC). offset
158 is the offset of the local timezone, in seconds west of UTC (negative
159 if the timezone is east of UTC).
160 Examples:
161
162 "1124706420 25200" (2005-08-22 03:27:00 -0700)
163
164 "1145475591 -7200" (2006-04-19 21:39:51 +0200)
165
166 130 ENVIRONMENT VARIABLES
167 131 ---------------------
168 132
169 133 HGEDITOR::
170 134 This is the name of the editor to use when committing. Defaults to the
171 135 value of EDITOR.
172 136
173 137 (deprecated, use .hgrc)
174 138
175 139 HGENCODING::
176 140 This overrides the default locale setting detected by Mercurial.
177 141 This setting is used to convert data including usernames,
178 142 changeset descriptions, tag names, and branches. This setting can
179 143 be overridden with the --encoding command-line option.
180 144
181 145 HGENCODINGMODE::
182 146 This sets Mercurial's behavior for handling unknown characters
183 147 while transcoding user inputs. The default is "strict", which
184 148 causes Mercurial to abort if it can't translate a character. Other
185 149 settings include "replace", which replaces unknown characters, and
186 150 "ignore", which drops them. This setting can be overridden with
187 151 the --encodingmode command-line option.
188 152
189 153 HGMERGE::
190 154 An executable to use for resolving merge conflicts. The program
191 155 will be executed with three arguments: local file, remote file,
192 156 ancestor file.
193 157
194 158 The default program is "hgmerge", which is a shell script provided
195 159 by Mercurial with some sensible defaults.
196 160
197 161 (deprecated, use .hgrc)
198 162
199 163 HGRCPATH::
200 164 A list of files or directories to search for hgrc files. Item
201 165 separator is ":" on Unix, ";" on Windows. If HGRCPATH is not set,
202 166 platform default search path is used. If empty, only .hg/hgrc of
203 167 current repository is read.
204 168
205 169 For each element in path, if a directory, all entries in directory
206 170 ending with ".rc" are added to path. Else, element itself is
207 171 added to path.
208 172
209 173 HGUSER::
210 174 This is the string used for the author of a commit.
211 175
212 176 (deprecated, use .hgrc)
213 177
214 178 EMAIL::
215 179 If HGUSER is not set, this will be used as the author for a commit.
216 180
217 181 LOGNAME::
218 182 If neither HGUSER nor EMAIL is set, LOGNAME will be used (with
219 183 '@hostname' appended) as the author value for a commit.
220 184
221 185 EDITOR::
222 186 This is the name of the editor used in the hgmerge script. It will be
223 187 used for commit messages if HGEDITOR isn't set. Defaults to 'vi'.
224 188
225 189 PYTHONPATH::
226 190 This is used by Python to find imported modules and may need to be set
227 191 appropriately if Mercurial is not installed system-wide.
228 192
229 193 FILES
230 194 -----
231 195 .hgignore::
232 196 This file contains regular expressions (one per line) that describe file
233 197 names that should be ignored by hg. For details, see hgignore(5).
234 198
235 199 .hgtags::
236 200 This file contains changeset hash values and text tag names (one of each
237 201 separated by spaces) that correspond to tagged versions of the repository
238 202 contents.
239 203
240 204 /etc/mercurial/hgrc, $HOME/.hgrc, .hg/hgrc::
241 205 This file contains defaults and configuration. Values in .hg/hgrc
242 206 override those in $HOME/.hgrc, and these override settings made in the
243 207 global /etc/mercurial/hgrc configuration. See hgrc(5) for details of
244 208 the contents and format of these files.
245 209
246 210 Some commands (e.g. revert) produce backup files ending in .orig, if
247 211 the .orig file already exists and is not tracked by Mercurial, it
248 212 will be overwritten.
249 213
250 214 BUGS
251 215 ----
252 216 Probably lots, please post them to the mailing list (See Resources below)
253 217 when you find them.
254 218
255 219 SEE ALSO
256 220 --------
257 221 hgignore(5), hgrc(5)
258 222
259 223 AUTHOR
260 224 ------
261 225 Written by Matt Mackall <mpm@selenic.com>
262 226
263 227 RESOURCES
264 228 ---------
265 229 http://selenic.com/mercurial[Main Web Site]
266 230
267 231 http://selenic.com/hg[Source code repository]
268 232
269 233 http://selenic.com/mailman/listinfo/mercurial[Mailing list]
270 234
271 235 COPYING
272 236 -------
273 237 Copyright \(C) 2005, 2006 Matt Mackall.
274 238 Free use of this software is granted under the terms of the GNU General
275 239 Public License (GPL).
General Comments 0
You need to be logged in to leave comments. Login now