Skip to content

Commit

Permalink
[fix] Validate app argument choice for input value too
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelebleu committed Dec 28, 2015
1 parent 4a06cbd commit 96f9ca9
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/yunohost/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1326,18 +1326,14 @@ def _parse_args_from_manifest(manifest, action, args={}, auth=None):
# Attempt to retrieve argument value
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('app_argument_choice_invalid',
name=arg_name, choices=', '.join(arg['choices'])))
else:
if os.isatty(1) and 'ask' in arg:
# Retrieve proper ask string
ask_string = _value_for_locale(arg['ask'])

# Append extra strings
if 'choices' in arg:
ask_string += ' ({:s})'.format('|'.join(arg['choices']))
ask_string += ' [{:s}]'.format(' | '.join(arg['choices']))
if 'default' in arg:
ask_string += ' (default: {:s})'.format(arg['default'])

Expand All @@ -1353,6 +1349,10 @@ def _parse_args_from_manifest(manifest, action, args={}, auth=None):
m18n.n('app_argument_missing', name=arg_name))

# Validate argument value
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'])))
# TODO: Add more type, e.g. boolean
arg_type = arg.get('type', 'string')
if arg_type == 'domain':
Expand Down

0 comments on commit 96f9ca9

Please sign in to comment.