Mercurial > hg
diff mercurial/cmdutil.py @ 21767:75a96326cecb
commands: add norepo argument to command decorator
Since decorators are evaluated at module load time and since the
@command decorator imports commands, the norepo variable (along with
its friends) may not be declared yet. These variables are now declared
before @command usage to ensure they are present.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 04 May 2014 20:58:25 -0700 |
parents | a039e1f2326f |
children | b280d0b60bc3 |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Sun May 04 18:45:04 2014 -0700 +++ b/mercurial/cmdutil.py Sun May 04 20:58:25 2014 -0700 @@ -2489,14 +2489,23 @@ The synopsis argument defines a short, one line summary of how to use the command. This shows up in the help output. + + The norepo argument defines whether the command does not require a + local repository. Most commands operate against a repository, thus the + default is False. """ - - def cmd(name, options=(), synopsis=None): + def cmd(name, options=(), synopsis=None, norepo=False): def decorator(func): if synopsis: table[name] = func, list(options), synopsis else: table[name] = func, list(options) + + if norepo: + # Avoid import cycle. + import commands + commands.norepo += ' %s' % ' '.join(parsealiases(name)) + return func return decorator