mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Adding actions to subcategory
This commit is contained in:
parent
f595c37a4a
commit
c01cef3147
2 changed files with 42 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue