##// END OF EJS Templates
extensions: allow extending command synopsis and docstring...
Ryan McElroy -
r24124:042d95be default
parent child Browse files
Show More
@@ -152,7 +152,7 b' def afterloaded(extension, callback):'
152 152 else:
153 153 _aftercallbacks.setdefault(extension, []).append(callback)
154 154
155 def wrapcommand(table, command, wrapper):
155 def wrapcommand(table, command, wrapper, synopsis=None, docstring=None):
156 156 '''Wrap the command named `command' in table
157 157
158 158 Replace command in the command table with wrapper. The wrapped command will
@@ -164,6 +164,22 b' def wrapcommand(table, command, wrapper)'
164 164
165 165 where orig is the original (wrapped) function, and *args, **kwargs
166 166 are the arguments passed to it.
167
168 Optionally append to the command synopsis and docstring, used for help.
169 For example, if your extension wraps the ``bookmarks`` command to add the
170 flags ``--remote`` and ``--all`` you might call this function like so:
171
172 synopsis = ' [-a] [--remote]'
173 docstring = """
174
175 The ``remotenames`` extension adds the ``--remote`` and ``--all`` (``-a``)
176 flags to the bookmarks command. Either flag will show the remote bookmarks
177 known to the repository; ``--remote`` will also supress the output of the
178 local bookmarks.
179 """
180
181 extensions.wrapcommand(commands.table, 'bookmarks', exbookmarks,
182 synopsis, docstring)
167 183 '''
168 184 assert callable(wrapper)
169 185 aliases, entry = cmdutil.findcmd(command, table)
@@ -177,11 +193,17 b' def wrapcommand(table, command, wrapper)'
177 193 return util.checksignature(wrapper)(
178 194 util.checksignature(origfn), *args, **kwargs)
179 195
180 wrap.__doc__ = getattr(origfn, '__doc__')
181 196 wrap.__module__ = getattr(origfn, '__module__')
182 197
198 doc = getattr(origfn, '__doc__')
199 if docstring is not None:
200 doc += docstring
201 wrap.__doc__ = doc
202
183 203 newentry = list(entry)
184 204 newentry[0] = wrap
205 if synopsis is not None:
206 newentry[2] += synopsis
185 207 table[key] = tuple(newentry)
186 208 return entry
187 209
@@ -1140,3 +1140,27 b' disabling in command line overlays with '
1140 1140 C sub3/3
1141 1141
1142 1142 $ cd ..
1143
1144 Test synopsis and docstring extending
1145
1146 $ hg init exthelp
1147 $ cat > exthelp.py <<EOF
1148 > from mercurial import commands, extensions
1149 > def exbookmarks(orig, *args, **opts):
1150 > return orig(*args, **opts)
1151 > def uisetup(ui):
1152 > synopsis = ' GREPME [--foo] [-x]'
1153 > docstring = '''
1154 > GREPME make sure that this is in the help!
1155 > '''
1156 > extensions.wrapcommand(commands.table, 'bookmarks', exbookmarks,
1157 > synopsis, docstring)
1158 > EOF
1159 $ abspath=`pwd`/exthelp.py
1160 $ echo '[extensions]' >> $HGRCPATH
1161 $ echo "exthelp = $abspath" >> $HGRCPATH
1162 $ cd exthelp
1163 $ hg help bookmarks | grep GREPME
1164 hg bookmarks [OPTIONS]... [NAME]... GREPME [--foo] [-x]
1165 GREPME make sure that this is in the help!
1166
General Comments 0
You need to be logged in to leave comments. Login now