def _person_opts(person, short):
"""Sets options.<person> to a function that modifies a Person
according to the commandline options."""
def short_callback(option, opt_str, value, parser, field):
f = getattr(parser.values, person)
if field == "date":
value = git.Date(value)
setattr(parser.values, person,
lambda p: getattr(f(p), 'set_' + field)(value))
def full_callback(option, opt_str, value, parser):
ne = utils.parse_name_email(value)
if not ne:
raise optparse.OptionValueError(
'Bad %s specification: %r' % (opt_str, value))
name, email = ne
short_callback(option, opt_str, name, parser, 'name')
short_callback(option, opt_str, email, parser, 'email')
return (
[opt('--%s' % person, metavar = '"NAME <EMAIL>"', type = 'string',
action = 'callback', callback = full_callback, dest = person,
default = lambda p: p, short = 'Set the %s details' % person)] +
[opt('--%s%s' % (short, f), metavar = f.upper(), type = 'string',
action = 'callback', callback = short_callback, dest = person,
callback_args = (f,), short = 'Set the %s %s' % (person, f))
for f in ['name', 'email', 'date']])
评论列表
文章目录