comparison mercurial/cmdutil.py @ 21777:17d1ac452127

cmdutil: support inferrepo in command decorator
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 04 May 2014 22:20:00 -0700
parents b280d0b60bc3
children 4b93e19cd6e6
comparison
equal deleted inserted replaced
21776:c4633e287c56 21777:17d1ac452127
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 2496
2497 The optionalrepo argument defines whether the command optionally requires 2497 The optionalrepo argument defines whether the command optionally requires
2498 a local repository. 2498 a local repository.
2499
2500 The inferrepo argument defines whether to try to find a repository from the
2501 command line arguments. If True, arguments will be examined for potential
2502 repository locations. See ``findrepo()``. If a repository is found, it
2503 will be used.
2499 """ 2504 """
2500 def cmd(name, options=(), synopsis=None, norepo=False, optionalrepo=False): 2505 def cmd(name, options=(), synopsis=None, norepo=False, optionalrepo=False,
2506 inferrepo=False):
2501 def decorator(func): 2507 def decorator(func):
2502 if synopsis: 2508 if synopsis:
2503 table[name] = func, list(options), synopsis 2509 table[name] = func, list(options), synopsis
2504 else: 2510 else:
2505 table[name] = func, list(options) 2511 table[name] = func, list(options)
2510 commands.norepo += ' %s' % ' '.join(parsealiases(name)) 2516 commands.norepo += ' %s' % ' '.join(parsealiases(name))
2511 2517
2512 if optionalrepo: 2518 if optionalrepo:
2513 import commands 2519 import commands
2514 commands.optionalrepo += ' %s' % ' '.join(parsealiases(name)) 2520 commands.optionalrepo += ' %s' % ' '.join(parsealiases(name))
2521
2522 if inferrepo:
2523 import commands
2524 commands.inferrepo += ' %s' % ' '.join(parsealiases(name))
2515 2525
2516 return func 2526 return func
2517 return decorator 2527 return decorator
2518 2528
2519 return cmd 2529 return cmd