diff --git a/locales/en.json b/locales/en.json index 37f49bf03..ae2dfb1dd 100644 --- a/locales/en.json +++ b/locales/en.json @@ -29,7 +29,9 @@ "app_extraction_failed" : "Unable to extract installation files", "app_install_files_invalid" : "Invalid installation files", "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_sources_fetch_failed" : "Unable to fetch sources files", "ssowat_conf_updated" : "SSOwat persistent configuration successfully updated", "ssowat_conf_generated" : "SSOwat configuration successfully generated", @@ -86,8 +88,6 @@ "hook_list_by_invalid" : "Invalid property to list hook by", "hook_name_unknown" : "Unknown hook name '{:s}'", - "hook_choice_invalid" : "Invalid choice '{:s}'", - "hook_argument_missing" : "Missing argument '{:s}'", "hook_exec_failed" : "Script execution failed", "hook_exec_not_terminated" : "Script execution hasn’t terminated", diff --git a/src/yunohost/app.py b/src/yunohost/app.py index 19e3cd94c..a0d2f1c07 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -1320,14 +1320,16 @@ def _parse_args_from_manifest(manifest, action, args={}, auth=None): logger.debug("no arguments found for '%s' in '%s'", action, path) else: for arg in action_args: + arg_name = arg['name'] arg_value = None # Attempt to retrieve argument value - if arg['name'] in args: - if 'choices' in arg and args[arg['name']] not in arg['choices']: + if arg_name in args: + arg_value = args[arg_name] + if 'choices' in arg and arg_value not in arg['choices']: raise MoulinetteError(errno.EINVAL, - m18n.n('hook_choice_invalid', args[arg['name']])) - arg_value = args[arg['name']] + m18n.n('app_argument_choice_invalid', + name=arg_name, choices=', '.join(arg['choices']))) else: if os.isatty(1) and 'ask' in arg: # Retrieve proper ask string @@ -1348,7 +1350,7 @@ def _parse_args_from_manifest(manifest, action, args={}, auth=None): arg_value = arg['default'] else: raise MoulinetteError(errno.EINVAL, - m18n.n('hook_argument_missing', arg['name'])) + m18n.n('app_argument_missing', name=arg_name)) # Validate argument value # TODO: Add more type, e.g. boolean @@ -1357,19 +1359,19 @@ def _parse_args_from_manifest(manifest, action, args={}, auth=None): if arg_value not in domain_list(auth)['domains']: raise MoulinetteError(errno.EINVAL, m18n.n('app_argument_invalid', - name=arg['name'], error=m18n.n('domain_unknown'))) + name=arg_name, error=m18n.n('domain_unknown'))) elif arg_type == 'user': try: user_info(auth, arg_value) except MoulinetteError as e: raise MoulinetteError(errno.EINVAL, m18n.n('app_argument_invalid', - name=arg['name'], error=e.strerror)) + name=arg_name, error=e.strerror)) elif arg_type == 'app': if not _is_installed(arg_value): raise MoulinetteError(errno.EINVAL, m18n.n('app_argument_invalid', - name=arg['name'], error=m18n.n('app_unknown'))) + name=arg_name, error=m18n.n('app_unknown'))) args_list.append(arg_value) return args_list