From c01cef3147ebf4e6b5c2f48ea652c8ad5aa11763 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sun, 23 Jul 2017 09:17:27 -0400 Subject: [PATCH] Adding actions to subcategory --- moulinette/actionsmap.py | 27 +++++++++++++++++++++++++++ moulinette/interfaces/cli.py | 15 +++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/moulinette/actionsmap.py b/moulinette/actionsmap.py index 35be7ac6..2a02cedd 100644 --- a/moulinette/actionsmap.py +++ b/moulinette/actionsmap.py @@ -657,5 +657,32 @@ class ActionsMap(object): print subcategory_name print subcategory_values + actions = subcategory_values.pop('actions') + + # Get subcategory parser + subcategory_parser = category_parser.add_subcategory_parser(subcategory_name, **subcategory_values) + + # action_name is like "status" of "domain cert status" + # action_options are the values + for action_name, action_options in actions.items(): + arguments = action_options.pop('arguments', {}) + tid = (namespace, category_name, subcategory_name, action_name) + + try: + # Get action parser + action_parser = subcategory_parser.add_action_parser(action_name, tid, **action_options) + except AttributeError: + # No parser for the action + continue + + # Store action identifier and add arguments + action_parser.set_defaults(_tid=tid) + _add_arguments(tid, action_parser, arguments) + + if 'configuration' in action_options: + configuration = action_options.pop('configuration') + subcategory_parser.set_conf(tid, configuration) + + return top_parser diff --git a/moulinette/interfaces/cli.py b/moulinette/interfaces/cli.py index 33468f00..433da026 100644 --- a/moulinette/interfaces/cli.py +++ b/moulinette/interfaces/cli.py @@ -271,6 +271,21 @@ class ActionsMapParser(BaseActionsMapParser): 'title': "actions", 'required': True }) + def add_subcategory_parser(self, name, subcategory_help=None, **kwargs): + """Add a parser for a subcategory + + Keyword arguments: + - subcategory_help -- A brief description for the category + + Returns: + A new ActionsMapParser object for the category + + """ + parser = self._subparsers.add_parser(name, help=subcategory_help, **kwargs) + return self.__class__(self, parser, { + 'title': "actions", 'required': True + }) + def add_action_parser(self, name, tid, action_help=None, deprecated=False, deprecated_alias=[], **kwargs): """Add a parser for an action