Show More
@@ -21,10 +21,57 b' from . import (' | |||||
21 | class exthelper(object): |
|
21 | class exthelper(object): | |
22 | """Helper for modular extension setup |
|
22 | """Helper for modular extension setup | |
23 |
|
23 | |||
24 |
A single helper should be instantiated for each |
|
24 | A single helper should be instantiated for each module of an | |
25 | methods are then used as decorators for various purpose. |
|
25 | extension, where a command or function needs to be wrapped, or a | |
|
26 | command, extension hook, fileset, revset or template needs to be | |||
|
27 | registered. Helper methods are then used as decorators for | |||
|
28 | these various purposes. If an extension spans multiple modules, | |||
|
29 | all helper instances should be merged in the main module. | |||
26 |
|
30 | |||
27 | All decorators return the original function and may be chained. |
|
31 | All decorators return the original function and may be chained. | |
|
32 | ||||
|
33 | Aside from the helper functions with examples below, several | |||
|
34 | registrar method aliases are available for adding commands, | |||
|
35 | configitems, filesets, revsets, and templates. Simply decorate | |||
|
36 | the appropriate methods, and assign the corresponding exthelper | |||
|
37 | variable to a module level variable of the extension. The | |||
|
38 | extension loading mechanism will handle the rest. | |||
|
39 | ||||
|
40 | example:: | |||
|
41 | ||||
|
42 | # ext.py | |||
|
43 | eh = exthelper.exthelper() | |||
|
44 | ||||
|
45 | # As needed: | |||
|
46 | cmdtable = eh.cmdtable | |||
|
47 | configtable = eh.configtable | |||
|
48 | filesetpredicate = eh.filesetpredicate | |||
|
49 | revsetpredicate = eh.revsetpredicate | |||
|
50 | templatekeyword = eh.templatekeyword | |||
|
51 | ||||
|
52 | @eh.command('mynewcommand', | |||
|
53 | [('r', 'rev', [], _('operate on these revisions'))], | |||
|
54 | _('-r REV...'), | |||
|
55 | helpcategory=command.CATEGORY_XXX) | |||
|
56 | def newcommand(ui, repo, *revs, **opts): | |||
|
57 | # implementation goes here | |||
|
58 | ||||
|
59 | eh.configitem('experimental', 'foo', | |||
|
60 | default=False, | |||
|
61 | ) | |||
|
62 | ||||
|
63 | @eh.filesetpredicate('lfs()') | |||
|
64 | def filesetbabar(mctx, x): | |||
|
65 | return mctx.predicate(...) | |||
|
66 | ||||
|
67 | @eh.revsetpredicate('hidden') | |||
|
68 | def revsetbabar(repo, subset, x): | |||
|
69 | args = revset.getargs(x, 0, 0, 'babar accept no argument') | |||
|
70 | return [r for r in subset if 'babar' in repo[r].description()] | |||
|
71 | ||||
|
72 | @eh.templatekeyword('babar') | |||
|
73 | def kwbabar(ctx): | |||
|
74 | return 'babar' | |||
28 | """ |
|
75 | """ | |
29 |
|
76 | |||
30 | def __init__(self): |
|
77 | def __init__(self): |
General Comments 0
You need to be logged in to leave comments.
Login now