From 9285976acc0a2bdadbd93494f9b9428977db6622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Sat, 2 Jan 2016 13:08:03 +0100 Subject: [PATCH] [enh] Integrate 'optional' key of arguments in app manifest --- locales/en.json | 2 +- src/yunohost/app.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/locales/en.json b/locales/en.json index 520e7660e..4c0dd51a5 100644 --- a/locales/en.json +++ b/locales/en.json @@ -31,7 +31,7 @@ "app_manifest_invalid" : "Invalid app manifest", "app_argument_choice_invalid" : "Invalid choice for argument '{name:s}', it must be one of {choices:s}", "app_argument_invalid" : "Invalid value for argument '{name:s}': {error:s}", - "app_argument_missing" : "Missing argument '{:s}'", + "app_argument_required" : "Argument '{name:s}' is required", "app_sources_fetch_failed" : "Unable to fetch sources files", "ssowat_conf_updated" : "SSOwat persistent configuration successfully updated", "ssowat_conf_generated" : "SSOwat configuration successfully generated", diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 13790dbd5..f43dd60be 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -1344,15 +1344,22 @@ def _parse_args_from_manifest(manifest, action, args={}, auth=None): arg_value = input_string elif 'default' in arg: arg_value = arg['default'] - else: - raise MoulinetteError(errno.EINVAL, - m18n.n('app_argument_missing', name=arg_name)) # Validate argument value + if not arg_value and not arg.get('optional', False): + raise MoulinetteError(errno.EINVAL, + m18n.n('app_argument_required', name=arg_name)) + elif not arg_value: + args_list.append('') + continue + + # Validate argument choice if 'choices' in arg and arg_value not in arg['choices']: raise MoulinetteError(errno.EINVAL, m18n.n('app_argument_choice_invalid', name=arg_name, choices=', '.join(arg['choices']))) + + # Validate argument type # TODO: Add more type, e.g. boolean arg_type = arg.get('type', 'string') if arg_type == 'domain':