mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Actions documentation
This commit is contained in:
parent
4e1dd30c4c
commit
49447517e3
1 changed files with 45 additions and 28 deletions
73
yunohost
73
yunohost
|
@ -34,6 +34,22 @@ gettext.install('YunoHost')
|
|||
from yunohost import YunoHostError, str_to_func, colorize
|
||||
|
||||
action_dict = {
|
||||
"""
|
||||
Category/actions dictionnary
|
||||
|
||||
Usage:
|
||||
Add your "'action' : 'help'" to a category of this dictionnary,
|
||||
and make sure the file yunohost_my-category.py exists in ./lib
|
||||
|
||||
Then create the function called category_action(args).
|
||||
|
||||
You can add some arguments with the function parse_args() below.
|
||||
|
||||
Example:
|
||||
'add' : 'Add user' refers to :
|
||||
user_add(args) function in lib/yunohost_user.py
|
||||
|
||||
"""
|
||||
'user' : {
|
||||
'help' : 'Manage users',
|
||||
'actions' : {
|
||||
|
@ -59,34 +75,6 @@ action_dict = {
|
|||
}
|
||||
}
|
||||
|
||||
def dict_to_parsers(action_dict):
|
||||
"""
|
||||
Turn action dictionnary to parser and subparsers (2 level)
|
||||
|
||||
Keyword arguments:
|
||||
action_dict -- Multi-level dictionnary of categories/actions list
|
||||
|
||||
Returns:
|
||||
Dictionnrary of parsers
|
||||
|
||||
"""
|
||||
# Intialize parsers
|
||||
parsers = subparsers_category = subparsers_action = {}
|
||||
parsers['general'] = argparse.ArgumentParser()
|
||||
subparsers = parsers['general'].add_subparsers()
|
||||
|
||||
# Compute dictionnary
|
||||
for category, info in action_dict.items():
|
||||
subparsers_category[category] = subparsers.add_parser(category, help=info['help'])
|
||||
subparsers_action[category] = subparsers_category[category].add_subparsers()
|
||||
for action, helper in info['actions'].items():
|
||||
parsers[category + '_' + action] = subparsers_action[category].add_parser(action, help=helper)
|
||||
parsers[category + '_' + action].set_defaults(
|
||||
func=str_to_func('yunohost_' + category + '.'
|
||||
+ category + '_' + action))
|
||||
|
||||
return parsers
|
||||
|
||||
def parse_args(parsers):
|
||||
"""
|
||||
Add and parse arguments
|
||||
|
@ -140,6 +128,35 @@ def parse_args(parsers):
|
|||
return args
|
||||
|
||||
|
||||
def dict_to_parsers(action_dict):
|
||||
"""
|
||||
Turn action dictionnary to parser and subparsers (2 level)
|
||||
|
||||
Keyword arguments:
|
||||
action_dict -- Multi-level dictionnary of categories/actions list
|
||||
|
||||
Returns:
|
||||
Dictionnrary of parsers
|
||||
|
||||
"""
|
||||
# Intialize parsers
|
||||
parsers = subparsers_category = subparsers_action = {}
|
||||
parsers['general'] = argparse.ArgumentParser()
|
||||
subparsers = parsers['general'].add_subparsers()
|
||||
|
||||
# Compute dictionnary
|
||||
for category, info in action_dict.items():
|
||||
subparsers_category[category] = subparsers.add_parser(category, help=info['help'])
|
||||
subparsers_action[category] = subparsers_category[category].add_subparsers()
|
||||
for action, helper in info['actions'].items():
|
||||
parsers[category + '_' + action] = subparsers_action[category].add_parser(action, help=helper)
|
||||
parsers[category + '_' + action].set_defaults(
|
||||
func=str_to_func('yunohost_' + category + '.'
|
||||
+ category + '_' + action))
|
||||
|
||||
return parsers
|
||||
|
||||
|
||||
def main():
|
||||
""" Main instructions """
|
||||
try:
|
||||
|
|
Loading…
Add table
Reference in a new issue