Mercurial > public > mercurial-scm > hg
diff mercurial/registrar.py @ 32337:46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
cmdutil.command wasn't a member of the registrar framework only for a
historical reason. Let's make that happen. This patch keeps cmdutil.command
as an alias for extension compatibility.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 09 Jan 2016 23:07:20 +0900 |
parents | bdda942f4b9c |
children | ec84db232fc2 |
line wrap: on
line diff
--- a/mercurial/registrar.py Sat May 13 17:53:55 2017 +0900 +++ b/mercurial/registrar.py Sat Jan 09 23:07:20 2016 +0900 @@ -96,6 +96,51 @@ """ pass +def command(table): + """Returns a function object to be used as a decorator for making commands. + + This function receives a command table as its argument. The table should + be a dict. + + The returned function can be used as a decorator for adding commands + to that command table. This function accepts multiple arguments to define + a command. + + The first argument is the command name. + + The options argument is an iterable of tuples defining command arguments. + See ``mercurial.fancyopts.fancyopts()`` for the format of each tuple. + + 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. + + The optionalrepo argument defines whether the command optionally requires + a local repository. + + The inferrepo argument defines whether to try to find a repository from the + command line arguments. If True, arguments will be examined for potential + repository locations. See ``findrepo()``. If a repository is found, it + will be used. + """ + def cmd(name, options=(), synopsis=None, norepo=False, optionalrepo=False, + inferrepo=False): + def decorator(func): + func.norepo = norepo + func.optionalrepo = optionalrepo + func.inferrepo = inferrepo + if synopsis: + table[name] = func, list(options), synopsis + else: + table[name] = func, list(options) + return func + return decorator + + return cmd + class revsetpredicate(_funcregistrarbase): """Decorator to register revset predicate