Mercurial > public > mercurial-scm > hg-stable
diff mercurial/cmdutil.py @ 14297:2daa5179e73f
commands: use a decorator to build table incrementally
this allows to define the table entries near the command functions
author | Adrian Buehlmann <adrian@cadifra.com> |
---|---|
date | Thu, 12 May 2011 08:14:04 +0200 |
parents | 1a791993ce59 |
children | b33f3e35efb0 |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Thu May 12 13:47:17 2011 +0200 +++ b/mercurial/cmdutil.py Thu May 12 08:14:04 2011 +0200 @@ -1251,3 +1251,18 @@ raise util.Abort(_("empty commit message")) return text + +def command(table): + '''returns a function object bound to table which can be used as + a decorator for populating table as a command table''' + + def cmd(name, options, synopsis=None): + def decorator(func): + if synopsis: + table[name] = func, options, synopsis + else: + table[name] = func, options + return func + return decorator + + return cmd