##// END OF EJS Templates
helptext: byteify extensions examples...
Matt Harbison -
r46543:f177fcd9 default
parent child Browse files
Show More
@@ -24,7 +24,8 b' Command table'
24 24
25 25 To write your own extension, your python module can provide an optional dict
26 26 named ``cmdtable`` with entries describing each command. A command should be
27 registered to the ``cmdtable`` by ``@command`` decorator.
27 registered to the ``cmdtable`` by ``@command`` decorator. All string-like
28 values must be the ``bytes`` type, and are thus prefixed with ``b``.
28 29
29 30 Example using ``@command`` decorator (requires Mercurial 1.9)::
30 31
@@ -39,10 +40,10 b' Example using ``@command`` decorator (re'
39 40 from mercurial import cmdutil
40 41 command = cmdutil.command(cmdtable)
41 42
42 @command('print-parents',
43 [('s', 'short', None, _('print short form')),
44 ('l', 'long', None, _('print long form'))],
45 _('[options] node'))
43 @command(b'print-parents',
44 [(b's', b'short', None, _(b'print short form')),
45 (b'l', b'long', None, _(b'print long form'))],
46 _(b'[options] node'))
46 47 def printparents(ui, repo, node, **opts):
47 48 ...
48 49
@@ -84,7 +85,7 b' If there is no repo to be associated wit'
84 85 ``repo`` passed, then ``norepo=True`` should be passed to the ``@command``
85 86 decorator::
86 87
87 @command('mycommand', [], norepo=True)
88 @command(b'mycommand', [], norepo=True)
88 89 def mycommand(ui, **opts):
89 90 ...
90 91
@@ -140,7 +141,7 b' Communicating with the user'
140 141 ===========================
141 142
142 143 Besides the ``ui`` methods, like ``ui.write(*msg)`` or
143 ``ui.prompt(msg, default="y")``, an extension can add help text for each
144 ``ui.prompt(msg, default=b"y")``, an extension can add help text for each
144 145 of its commands and the extension itself.
145 146
146 147 The module docstring will be used as help string when ``hg help extensionname``
@@ -248,7 +249,7 b' For example::'
248 249 class echologui(ui.__class__):
249 250 def log(self, service, *msg, **opts):
250 251 if msg:
251 self.write('%s: %s\n' % (service, msg[0] % msg[1:]))
252 self.write(b'%s: %s\n' % (service, msg[0] % msg[1:]))
252 253 super(echologui, self).log(service, *msg, **opts)
253 254
254 255 ui.__class__ = echologui
@@ -259,7 +260,7 b' Configuring Hooks'
259 260 Some extensions must use hooks to do their work. These required hooks can
260 261 be configured manually by the user by modifying the ``[hook]`` section of
261 262 their hgrc, but they can also be configured automatically by calling the
262 ``ui.setconfig('hooks', ...)`` function in one of the setup functions
263 ``ui.setconfig(b'hooks', ...)`` function in one of the setup functions
263 264 described above.
264 265
265 266 The main difference between manually modifying the hooks section in the hgrc
@@ -273,21 +274,21 b' For example::'
273 274
274 275 # Define hooks -- note that the actual function name it irrelevant.
275 276 def preupdatehook(ui, repo, **kwargs):
276 ui.write("Pre-update hook triggered\n")
277 ui.write(b"Pre-update hook triggered\n")
277 278
278 279 def updatehook(ui, repo, **kwargs):
279 ui.write("Update hook triggered\n")
280 ui.write(b"Update hook triggered\n")
280 281
281 282 def uisetup(ui):
282 283 # When pre-<cmd> and post-<cmd> hooks are configured by means of
283 284 # the ui.setconfig() function, you must use the ui object passed
284 285 # to uisetup or extsetup.
285 ui.setconfig("hooks", "pre-update.myextension", preupdatehook)
286 ui.setconfig(b"hooks", b"pre-update.myextension", preupdatehook)
286 287
287 288 def reposetup(ui, repo):
288 289 # Repository-specific hooks can be configured here. These include
289 290 # the update hook.
290 ui.setconfig("hooks", "update.myextension", updatehook)
291 ui.setconfig(b"hooks", b"update.myextension", updatehook)
291 292
292 293 Note how different hooks may need to be configured in different setup
293 294 functions. In the example you can see that the ``update`` hook must be
@@ -301,7 +302,7 b' Every extension should use the ``testedw'
301 302 releases it's known to be compatible with. This helps us and users diagnose
302 303 where problems are coming from::
303 304
304 testedwith = '2.0 2.0.1 2.1 2.1.1 2.1.2'
305 testedwith = b'2.0 2.0.1 2.1 2.1.1 2.1.2'
305 306
306 307 Do not use the ``internal`` marker in third-party extensions; we will
307 308 immediately drop all bug reports mentioning your extension if we catch you
@@ -311,12 +312,12 b' Similarly, an extension can use the ``bu'
311 312 should report issues with the extension. This link will be included in the
312 313 error message if the extension produces errors::
313 314
314 buglink = 'https://bitbucket.org/USER/REPO/issues'
315 buglink = b'https://bitbucket.org/USER/REPO/issues'
315 316
316 317 If an extension requires a minimum version of Mercurial, it can be declared
317 318 with the ``minimumhgversion`` variable::
318 319
319 minimumhgversion = '4.6'
320 minimumhgversion = b'4.6'
320 321
321 322 Older clients will print a warning that the extension requires a new version,
322 323 instead of attempting to load it.
@@ -347,7 +348,7 b' uisetup'
347 348 extsetup
348 349 --------
349 350
350 * Changes depending on the status of other extensions. (``if extensions.find('mq')``)
351 * Changes depending on the status of other extensions. (``if extensions.find(b'mq')``)
351 352 * Add a global option to all commands
352 353 * Extend revsets
353 354
General Comments 0
You need to be logged in to leave comments. Login now