comparison 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
comparison
equal deleted inserted replaced
21766:a039e1f2326f 21767:75a96326cecb
2487 The options argument is an iterable of tuples defining command arguments. 2487 The options argument is an iterable of tuples defining command arguments.
2488 See ``mercurial.fancyopts.fancyopts()`` for the format of each tuple. 2488 See ``mercurial.fancyopts.fancyopts()`` for the format of each tuple.
2489 2489
2490 The synopsis argument defines a short, one line summary of how to use the 2490 The synopsis argument defines a short, one line summary of how to use the
2491 command. This shows up in the help output. 2491 command. This shows up in the help output.
2492
2493 The norepo argument defines whether the command does not require a
2494 local repository. Most commands operate against a repository, thus the
2495 default is False.
2492 """ 2496 """
2493 2497 def cmd(name, options=(), synopsis=None, norepo=False):
2494 def cmd(name, options=(), synopsis=None):
2495 def decorator(func): 2498 def decorator(func):
2496 if synopsis: 2499 if synopsis:
2497 table[name] = func, list(options), synopsis 2500 table[name] = func, list(options), synopsis
2498 else: 2501 else:
2499 table[name] = func, list(options) 2502 table[name] = func, list(options)
2503
2504 if norepo:
2505 # Avoid import cycle.
2506 import commands
2507 commands.norepo += ' %s' % ' '.join(parsealiases(name))
2508
2500 return func 2509 return func
2501 return decorator 2510 return decorator
2502 2511
2503 return cmd 2512 return cmd
2504 2513