Skip to content
This repository has been archived by the owner on Jul 20, 2020. It is now read-only.

Commit

Permalink
Issue-#3 Allow multiples of --hashtag, --added, --removed flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
nils.diefenbach committed Sep 7, 2018
1 parent 9cc5772 commit 2e2cb32
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
22 changes: 21 additions & 1 deletion gerrit_hooks/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,27 @@ def __getitem__(self, item):
:rtype: Dict
"""
flag_string = self.__mapping__[item]
flag_configuration = {}
for match in self.FLAG_PATTERN.finditer(flag_string):
flag, description = match.flag, match.description
options = {}
if (flag in ('--hashtag', '--added', '--removed')
and item == SupportedHooks.HASHTAGS_CHANGED):
# These flags may be passed several times; therefore, we need
# to store them multiple times. The 'append' action appends
# the passed value as a List[str] to the related flag variable
# in the namespace. For example::
#
# hashtag-changes --hashtag hello --hashtag wonky
#
# would result in ::
#
# >>>options = parse_options()
# >>>options.hashtag
# [['hello'], ['wonky']]
options.update({'nargs': '1', 'action': 'append'})
flag_configuration[flag] = description, options
return {
match.flag: match.description
match.flag: (match.description, {})
for match in self.FLAG_PATTERN.finditer(flag_string)
}
4 changes: 2 additions & 2 deletions gerrit_hooks/hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def _generate_parser(**cli_kwargs):
:rtype: argparse.ArgumentParser
"""
parser = argparse.ArgumentParser()
for flag, description in cli_kwargs.items():
parser.add_argument(flag, description=description)
for flag, description, options in cli_kwargs.items():
parser.add_argument(flag, description=description, **options)
return parser


Expand Down

0 comments on commit 2e2cb32

Please sign in to comment.