Mercurial > hg-stable
annotate mercurial/registrar.py @ 32377:ec84db232fc2
registrar: switch @command decorator to class
It overrides _funcregistrarbase._doregister() since the structure of the
command table is quite different.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 08 May 2017 22:08:40 +0900 |
parents | 46ba2cdda476 |
children | 92de09a05d7f |
rev | line source |
---|---|
27583
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
1 # registrar.py - utilities to register function for specific purpose |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
2 # |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
3 # Copyright FUJIWARA Katsunori <foozy@lares.dti.ne.jp> and others |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
4 # |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
7 |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
8 from __future__ import absolute_import |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
9 |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
10 from . import ( |
30613
b52e8a4f4c0f
registrar: raise a programming error on duplicated registering
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30342
diff
changeset
|
11 error, |
30059
6ffb7e0249f4
registrar: make format strings unicodes and not bytes
Augie Fackler <augie@google.com>
parents:
29937
diff
changeset
|
12 pycompat, |
27583
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
13 util, |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
14 ) |
37d50250b696
registrar: add funcregistrar class to register function for specific purpose
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
15 |
28392
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
16 class _funcregistrarbase(object): |
30342
318a24b52eeb
spelling: fixes of non-dictionary words
Mads Kiilerich <madski@unity3d.com>
parents:
30059
diff
changeset
|
17 """Base of decorator to register a function for specific purpose |
28392
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
18 |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
19 This decorator stores decorated functions into own dict 'table'. |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
20 |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
21 The least derived class can be defined by overriding 'formatdoc', |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
22 for example:: |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
23 |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
24 class keyword(_funcregistrarbase): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
25 _docformat = ":%s: %s" |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
26 |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
27 This should be used as below: |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
28 |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
29 keyword = registrar.keyword() |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
30 |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
31 @keyword('bar') |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
32 def barfunc(*args, **kwargs): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
33 '''Explanation of bar keyword .... |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
34 ''' |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
35 pass |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
36 |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
37 In this case: |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
38 |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
39 - 'barfunc' is stored as 'bar' in '_table' of an instance 'keyword' above |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
40 - 'barfunc.__doc__' becomes ":bar: Explanation of bar keyword" |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
41 """ |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
42 def __init__(self, table=None): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
43 if table is None: |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
44 self._table = {} |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
45 else: |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
46 self._table = table |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
47 |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
48 def __call__(self, decl, *args, **kwargs): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
49 return lambda func: self._doregister(func, decl, *args, **kwargs) |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
50 |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
51 def _doregister(self, func, decl, *args, **kwargs): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
52 name = self._getname(decl) |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
53 |
30613
b52e8a4f4c0f
registrar: raise a programming error on duplicated registering
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30342
diff
changeset
|
54 if name in self._table: |
b52e8a4f4c0f
registrar: raise a programming error on duplicated registering
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30342
diff
changeset
|
55 msg = 'duplicate registration for name: "%s"' % name |
b52e8a4f4c0f
registrar: raise a programming error on duplicated registering
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30342
diff
changeset
|
56 raise error.ProgrammingError(msg) |
b52e8a4f4c0f
registrar: raise a programming error on duplicated registering
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
30342
diff
changeset
|
57 |
28392
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
58 if func.__doc__ and not util.safehasattr(func, '_origdoc'): |
31820
45761ef1bc93
py3: have registrar process docstrings in bytes
Yuya Nishihara <yuya@tcha.org>
parents:
30613
diff
changeset
|
59 doc = pycompat.sysbytes(func.__doc__).strip() |
28392
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
60 func._origdoc = doc |
31820
45761ef1bc93
py3: have registrar process docstrings in bytes
Yuya Nishihara <yuya@tcha.org>
parents:
30613
diff
changeset
|
61 func.__doc__ = pycompat.sysstr(self._formatdoc(decl, doc)) |
28392
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
62 |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
63 self._table[name] = func |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
64 self._extrasetup(name, func, *args, **kwargs) |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
65 |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
66 return func |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
67 |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
68 def _parsefuncdecl(self, decl): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
69 """Parse function declaration and return the name of function in it |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
70 """ |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
71 i = decl.find('(') |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
72 if i >= 0: |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
73 return decl[:i] |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
74 else: |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
75 return decl |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
76 |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
77 def _getname(self, decl): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
78 """Return the name of the registered function from decl |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
79 |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
80 Derived class should override this, if it allows more |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
81 descriptive 'decl' string than just a name. |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
82 """ |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
83 return decl |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
84 |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
85 _docformat = None |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
86 |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
87 def _formatdoc(self, decl, doc): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
88 """Return formatted document of the registered function for help |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
89 |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
90 'doc' is '__doc__.strip()' of the registered function. |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
91 """ |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
92 return self._docformat % (decl, doc) |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
93 |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
94 def _extrasetup(self, name, func): |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
95 """Execute exra setup for registered function, if needed |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
96 """ |
b983a2f04987
registrar: introduce new class for registration to replace funcregistrar
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27585
diff
changeset
|
97 pass |
28393
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
98 |
32377
ec84db232fc2
registrar: switch @command decorator to class
Yuya Nishihara <yuya@tcha.org>
parents:
32376
diff
changeset
|
99 class command(_funcregistrarbase): |
ec84db232fc2
registrar: switch @command decorator to class
Yuya Nishihara <yuya@tcha.org>
parents:
32376
diff
changeset
|
100 """Decorator to register a command function to table |
32376
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
101 |
32377
ec84db232fc2
registrar: switch @command decorator to class
Yuya Nishihara <yuya@tcha.org>
parents:
32376
diff
changeset
|
102 This class receives a command table as its argument. The table should |
32376
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
103 be a dict. |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
104 |
32377
ec84db232fc2
registrar: switch @command decorator to class
Yuya Nishihara <yuya@tcha.org>
parents:
32376
diff
changeset
|
105 The created object can be used as a decorator for adding commands to |
ec84db232fc2
registrar: switch @command decorator to class
Yuya Nishihara <yuya@tcha.org>
parents:
32376
diff
changeset
|
106 that command table. This accepts multiple arguments to define a command. |
32376
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
107 |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
108 The first argument is the command name. |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
109 |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
110 The options argument is an iterable of tuples defining command arguments. |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
111 See ``mercurial.fancyopts.fancyopts()`` for the format of each tuple. |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
112 |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
113 The synopsis argument defines a short, one line summary of how to use the |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
114 command. This shows up in the help output. |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
115 |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
116 The norepo argument defines whether the command does not require a |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
117 local repository. Most commands operate against a repository, thus the |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
118 default is False. |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
119 |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
120 The optionalrepo argument defines whether the command optionally requires |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
121 a local repository. |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
122 |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
123 The inferrepo argument defines whether to try to find a repository from the |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
124 command line arguments. If True, arguments will be examined for potential |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
125 repository locations. See ``findrepo()``. If a repository is found, it |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
126 will be used. |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
127 """ |
32377
ec84db232fc2
registrar: switch @command decorator to class
Yuya Nishihara <yuya@tcha.org>
parents:
32376
diff
changeset
|
128 |
ec84db232fc2
registrar: switch @command decorator to class
Yuya Nishihara <yuya@tcha.org>
parents:
32376
diff
changeset
|
129 def _doregister(self, func, name, options=(), synopsis=None, |
ec84db232fc2
registrar: switch @command decorator to class
Yuya Nishihara <yuya@tcha.org>
parents:
32376
diff
changeset
|
130 norepo=False, optionalrepo=False, inferrepo=False): |
ec84db232fc2
registrar: switch @command decorator to class
Yuya Nishihara <yuya@tcha.org>
parents:
32376
diff
changeset
|
131 if True: |
32376
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
132 func.norepo = norepo |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
133 func.optionalrepo = optionalrepo |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
134 func.inferrepo = inferrepo |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
135 if synopsis: |
32377
ec84db232fc2
registrar: switch @command decorator to class
Yuya Nishihara <yuya@tcha.org>
parents:
32376
diff
changeset
|
136 self._table[name] = func, list(options), synopsis |
32376
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
137 else: |
32377
ec84db232fc2
registrar: switch @command decorator to class
Yuya Nishihara <yuya@tcha.org>
parents:
32376
diff
changeset
|
138 self._table[name] = func, list(options) |
32376
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
139 return func |
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
31886
diff
changeset
|
140 |
28393
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
141 class revsetpredicate(_funcregistrarbase): |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
142 """Decorator to register revset predicate |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
143 |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
144 Usage:: |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
145 |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
146 revsetpredicate = registrar.revsetpredicate() |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
147 |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
148 @revsetpredicate('mypredicate(arg1, arg2[, arg3])') |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
149 def mypredicatefunc(repo, subset, x): |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
150 '''Explanation of this revset predicate .... |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
151 ''' |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
152 pass |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
153 |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
154 The first string argument is used also in online help. |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
155 |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
156 Optional argument 'safe' indicates whether a predicate is safe for |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
157 DoS attack (False by default). |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
158 |
29937
91a95ad985d8
revset: add 'takeorder' attribute to mark functions that need ordering flag
Yuya Nishihara <yuya@tcha.org>
parents:
28695
diff
changeset
|
159 Optional argument 'takeorder' indicates whether a predicate function |
91a95ad985d8
revset: add 'takeorder' attribute to mark functions that need ordering flag
Yuya Nishihara <yuya@tcha.org>
parents:
28695
diff
changeset
|
160 takes ordering policy as the last argument. |
91a95ad985d8
revset: add 'takeorder' attribute to mark functions that need ordering flag
Yuya Nishihara <yuya@tcha.org>
parents:
28695
diff
changeset
|
161 |
28393
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
162 'revsetpredicate' instance in example above can be used to |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
163 decorate multiple functions. |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
164 |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
165 Decorated functions are registered automatically at loading |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
166 extension, if an instance named as 'revsetpredicate' is used for |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
167 decorating in extension. |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
168 |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
169 Otherwise, explicit 'revset.loadpredicate()' is needed. |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
170 """ |
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
171 _getname = _funcregistrarbase._parsefuncdecl |
31820
45761ef1bc93
py3: have registrar process docstrings in bytes
Yuya Nishihara <yuya@tcha.org>
parents:
30613
diff
changeset
|
172 _docformat = "``%s``\n %s" |
28393
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
173 |
29937
91a95ad985d8
revset: add 'takeorder' attribute to mark functions that need ordering flag
Yuya Nishihara <yuya@tcha.org>
parents:
28695
diff
changeset
|
174 def _extrasetup(self, name, func, safe=False, takeorder=False): |
28393
ac11ba7c2e56
registrar: define revsetpredicate to decorate revset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28392
diff
changeset
|
175 func._safe = safe |
29937
91a95ad985d8
revset: add 'takeorder' attribute to mark functions that need ordering flag
Yuya Nishihara <yuya@tcha.org>
parents:
28695
diff
changeset
|
176 func._takeorder = takeorder |
28447
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
177 |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
178 class filesetpredicate(_funcregistrarbase): |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
179 """Decorator to register fileset predicate |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
180 |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
181 Usage:: |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
182 |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
183 filesetpredicate = registrar.filesetpredicate() |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
184 |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
185 @filesetpredicate('mypredicate()') |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
186 def mypredicatefunc(mctx, x): |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
187 '''Explanation of this fileset predicate .... |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
188 ''' |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
189 pass |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
190 |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
191 The first string argument is used also in online help. |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
192 |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
193 Optional argument 'callstatus' indicates whether a predicate |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
194 implies 'matchctx.status()' at runtime or not (False, by |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
195 default). |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
196 |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
197 Optional argument 'callexisting' indicates whether a predicate |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
198 implies 'matchctx.existing()' at runtime or not (False, by |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
199 default). |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
200 |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
201 'filesetpredicate' instance in example above can be used to |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
202 decorate multiple functions. |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
203 |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
204 Decorated functions are registered automatically at loading |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
205 extension, if an instance named as 'filesetpredicate' is used for |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
206 decorating in extension. |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
207 |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
208 Otherwise, explicit 'fileset.loadpredicate()' is needed. |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
209 """ |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
210 _getname = _funcregistrarbase._parsefuncdecl |
31820
45761ef1bc93
py3: have registrar process docstrings in bytes
Yuya Nishihara <yuya@tcha.org>
parents:
30613
diff
changeset
|
211 _docformat = "``%s``\n %s" |
28447
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
212 |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
213 def _extrasetup(self, name, func, callstatus=False, callexisting=False): |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
214 func._callstatus = callstatus |
4eb5496c2bd4
registrar: add filesetpredicate to mark a function as fileset predicate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28446
diff
changeset
|
215 func._callexisting = callexisting |
28538
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
216 |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
217 class _templateregistrarbase(_funcregistrarbase): |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
218 """Base of decorator to register functions as template specific one |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
219 """ |
31820
45761ef1bc93
py3: have registrar process docstrings in bytes
Yuya Nishihara <yuya@tcha.org>
parents:
30613
diff
changeset
|
220 _docformat = ":%s: %s" |
28538
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
221 |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
222 class templatekeyword(_templateregistrarbase): |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
223 """Decorator to register template keyword |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
224 |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
225 Usage:: |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
226 |
30342
318a24b52eeb
spelling: fixes of non-dictionary words
Mads Kiilerich <madski@unity3d.com>
parents:
30059
diff
changeset
|
227 templatekeyword = registrar.templatekeyword() |
28538
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
228 |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
229 @templatekeyword('mykeyword') |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
230 def mykeywordfunc(repo, ctx, templ, cache, revcache, **args): |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
231 '''Explanation of this template keyword .... |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
232 ''' |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
233 pass |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
234 |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
235 The first string argument is used also in online help. |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
236 |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
237 'templatekeyword' instance in example above can be used to |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
238 decorate multiple functions. |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
239 |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
240 Decorated functions are registered automatically at loading |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
241 extension, if an instance named as 'templatekeyword' is used for |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
242 decorating in extension. |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
243 |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
244 Otherwise, explicit 'templatekw.loadkeyword()' is needed. |
009f58f1ea75
registrar: add templatekeyword to mark a function as template keyword (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28447
diff
changeset
|
245 """ |
28692
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
246 |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
247 class templatefilter(_templateregistrarbase): |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
248 """Decorator to register template filer |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
249 |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
250 Usage:: |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
251 |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
252 templatefilter = registrar.templatefilter() |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
253 |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
254 @templatefilter('myfilter') |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
255 def myfilterfunc(text): |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
256 '''Explanation of this template filter .... |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
257 ''' |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
258 pass |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
259 |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
260 The first string argument is used also in online help. |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
261 |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
262 'templatefilter' instance in example above can be used to |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
263 decorate multiple functions. |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
264 |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
265 Decorated functions are registered automatically at loading |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
266 extension, if an instance named as 'templatefilter' is used for |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
267 decorating in extension. |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
268 |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
269 Otherwise, explicit 'templatefilters.loadkeyword()' is needed. |
6b3b958daf03
registrar: add templatefilter to mark a function as template filter (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28538
diff
changeset
|
270 """ |
28695
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
271 |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
272 class templatefunc(_templateregistrarbase): |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
273 """Decorator to register template function |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
274 |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
275 Usage:: |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
276 |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
277 templatefunc = registrar.templatefunc() |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
278 |
31886
bdda942f4b9c
templater: add support for keyword arguments
Yuya Nishihara <yuya@tcha.org>
parents:
31820
diff
changeset
|
279 @templatefunc('myfunc(arg1, arg2[, arg3])', argspec='arg1 arg2 arg3') |
28695
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
280 def myfuncfunc(context, mapping, args): |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
281 '''Explanation of this template function .... |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
282 ''' |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
283 pass |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
284 |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
285 The first string argument is used also in online help. |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
286 |
31886
bdda942f4b9c
templater: add support for keyword arguments
Yuya Nishihara <yuya@tcha.org>
parents:
31820
diff
changeset
|
287 If optional 'argspec' is defined, the function will receive 'args' as |
bdda942f4b9c
templater: add support for keyword arguments
Yuya Nishihara <yuya@tcha.org>
parents:
31820
diff
changeset
|
288 a dict of named arguments. Otherwise 'args' is a list of positional |
bdda942f4b9c
templater: add support for keyword arguments
Yuya Nishihara <yuya@tcha.org>
parents:
31820
diff
changeset
|
289 arguments. |
bdda942f4b9c
templater: add support for keyword arguments
Yuya Nishihara <yuya@tcha.org>
parents:
31820
diff
changeset
|
290 |
28695
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
291 'templatefunc' instance in example above can be used to |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
292 decorate multiple functions. |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
293 |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
294 Decorated functions are registered automatically at loading |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
295 extension, if an instance named as 'templatefunc' is used for |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
296 decorating in extension. |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
297 |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
298 Otherwise, explicit 'templater.loadfunction()' is needed. |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
299 """ |
cc103bd0dbf9
registrar: add templatefunc to mark a function as template function (API)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28692
diff
changeset
|
300 _getname = _funcregistrarbase._parsefuncdecl |
31886
bdda942f4b9c
templater: add support for keyword arguments
Yuya Nishihara <yuya@tcha.org>
parents:
31820
diff
changeset
|
301 |
bdda942f4b9c
templater: add support for keyword arguments
Yuya Nishihara <yuya@tcha.org>
parents:
31820
diff
changeset
|
302 def _extrasetup(self, name, func, argspec=None): |
bdda942f4b9c
templater: add support for keyword arguments
Yuya Nishihara <yuya@tcha.org>
parents:
31820
diff
changeset
|
303 func._argspec = argspec |