comparison 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
comparison
equal deleted inserted replaced
14296:62e25c63fb3a 14297:2daa5179e73f
1249 1249
1250 if not text.strip(): 1250 if not text.strip():
1251 raise util.Abort(_("empty commit message")) 1251 raise util.Abort(_("empty commit message"))
1252 1252
1253 return text 1253 return text
1254
1255 def command(table):
1256 '''returns a function object bound to table which can be used as
1257 a decorator for populating table as a command table'''
1258
1259 def cmd(name, options, synopsis=None):
1260 def decorator(func):
1261 if synopsis:
1262 table[name] = func, options, synopsis
1263 else:
1264 table[name] = func, options
1265 return func
1266 return decorator
1267
1268 return cmd