cmdutil: add optionalrepo argument to command decorator
authorGregory Szorc <gregory.szorc@gmail.com>
Sun, 04 May 2014 22:12:34 -0700
changeset 21774 b280d0b60bc3
parent 21773 26d2fb899637
child 21775 5403245edb3a
cmdutil: add optionalrepo argument to command decorator
mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Sun May 04 22:07:45 2014 -0700
+++ b/mercurial/cmdutil.py	Sun May 04 22:12:34 2014 -0700
@@ -2493,8 +2493,11 @@
     The norepo argument defines whether the command does not require a
     local repository. Most commands operate against a repository, thus the
     default is False.
+
+    The optionalrepo argument defines whether the command optionally requires
+    a local repository.
     """
-    def cmd(name, options=(), synopsis=None, norepo=False):
+    def cmd(name, options=(), synopsis=None, norepo=False, optionalrepo=False):
         def decorator(func):
             if synopsis:
                 table[name] = func, list(options), synopsis
@@ -2506,6 +2509,10 @@
                 import commands
                 commands.norepo += ' %s' % ' '.join(parsealiases(name))
 
+            if optionalrepo:
+                import commands
+                commands.optionalrepo += ' %s' % ' '.join(parsealiases(name))
+
             return func
         return decorator