Allow aliasing a hook and calling it by it's alias

This commit is contained in:
Pedro Algarvio
2018-12-14 12:29:52 +00:00
parent c5c0a0699b
commit b096c0b8f2
3 changed files with 49 additions and 3 deletions

View File

@@ -29,6 +29,20 @@ def _make_argparser(filenames_help):
return parser
class OptionalAlias(object):
def check(self, dct):
if 'alias' in dct:
cfgv.check_string(dct['alias'])
def apply_default(self, dct):
if 'alias' not in dct:
dct['alias'] = dct['id']
def remove_default(self, dct):
pass
MANIFEST_HOOK_DICT = cfgv.Map(
'Hook', 'id',
@@ -36,6 +50,7 @@ MANIFEST_HOOK_DICT = cfgv.Map(
cfgv.Required('name', cfgv.check_string),
cfgv.Required('entry', cfgv.check_string),
cfgv.Required('language', cfgv.check_one_of(all_languages)),
cfgv.OptionalNoDefault('alias', cfgv.check_string),
cfgv.Optional(
'files', cfgv.check_and(cfgv.check_string, cfgv.check_regex), '',
@@ -125,6 +140,7 @@ CONFIG_HOOK_DICT = cfgv.Map(
'Hook', 'id',
cfgv.Required('id', cfgv.check_string),
OptionalAlias(),
# All keys in manifest hook dict are valid in a config hook dict, but
# are optional.
@@ -133,7 +149,7 @@ CONFIG_HOOK_DICT = cfgv.Map(
*[
cfgv.OptionalNoDefault(item.key, item.check_fn)
for item in MANIFEST_HOOK_DICT.items
if item.key != 'id'
if item.key not in ('id', 'alias')
]
)
CONFIG_REPO_DICT = cfgv.Map(