comparison mercurial/cmdutil.py @ 21774:b280d0b60bc3

cmdutil: add optionalrepo argument to command decorator
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 04 May 2014 22:12:34 -0700
parents 75a96326cecb
children 17d1ac452127
comparison
equal deleted inserted replaced
21773:26d2fb899637 21774:b280d0b60bc3
2491 command. This shows up in the help output. 2491 command. This shows up in the help output.
2492 2492
2493 The norepo argument defines whether the command does not require a 2493 The norepo argument defines whether the command does not require a
2494 local repository. Most commands operate against a repository, thus the 2494 local repository. Most commands operate against a repository, thus the
2495 default is False. 2495 default is False.
2496
2497 The optionalrepo argument defines whether the command optionally requires
2498 a local repository.
2496 """ 2499 """
2497 def cmd(name, options=(), synopsis=None, norepo=False): 2500 def cmd(name, options=(), synopsis=None, norepo=False, optionalrepo=False):
2498 def decorator(func): 2501 def decorator(func):
2499 if synopsis: 2502 if synopsis:
2500 table[name] = func, list(options), synopsis 2503 table[name] = func, list(options), synopsis
2501 else: 2504 else:
2502 table[name] = func, list(options) 2505 table[name] = func, list(options)
2503 2506
2504 if norepo: 2507 if norepo:
2505 # Avoid import cycle. 2508 # Avoid import cycle.
2506 import commands 2509 import commands
2507 commands.norepo += ' %s' % ' '.join(parsealiases(name)) 2510 commands.norepo += ' %s' % ' '.join(parsealiases(name))
2511
2512 if optionalrepo:
2513 import commands
2514 commands.optionalrepo += ' %s' % ' '.join(parsealiases(name))
2508 2515
2509 return func 2516 return func
2510 return decorator 2517 return decorator
2511 2518
2512 return cmd 2519 return cmd