Merge pull request #498 from YunoHost/real_cli_argument_for_boolean_type

[ux] display human understandable choice for boolean type on installation
This commit is contained in:
Bram 2018-06-30 15:35:48 +02:00 committed by GitHub
commit d1ac2f218b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2069,10 +2069,14 @@ def _parse_action_args_in_yunohost_format(args, action_args, auth=None):
# Append extra strings # Append extra strings
if arg_type == 'boolean': if arg_type == 'boolean':
ask_string += ' [0 | 1]' ask_string += ' [yes | no]'
elif arg_choices: elif arg_choices:
ask_string += ' [{0}]'.format(' | '.join(arg_choices)) ask_string += ' [{0}]'.format(' | '.join(arg_choices))
if arg_default is not None: if arg_default is not None:
if arg_type == 'boolean':
ask_string += ' (default: {0})'.format("yes" if arg_default == 1 else "no")
else:
ask_string += ' (default: {0})'.format(arg_default) ask_string += ' (default: {0})'.format(arg_default)
# Check for a password argument # Check for a password argument
@ -2134,14 +2138,14 @@ def _parse_action_args_in_yunohost_format(args, action_args, auth=None):
if isinstance(arg_value, bool): if isinstance(arg_value, bool):
arg_value = 1 if arg_value else 0 arg_value = 1 if arg_value else 0
else: else:
try: if str(arg_value).lower() in ["1", "yes", "y"]:
arg_value = int(arg_value) arg_value = 1
if arg_value not in [0, 1]: elif str(arg_value).lower() in ["0", "no", "n"]:
raise ValueError() arg_value = 0
except (TypeError, ValueError): else:
raise MoulinetteError(errno.EINVAL, raise MoulinetteError(errno.EINVAL,
m18n.n('app_argument_choice_invalid', m18n.n('app_argument_choice_invalid',
name=arg_name, choices='0, 1')) name=arg_name, choices='yes, no, y, n, 1, 0'))
args_dict[arg_name] = arg_value args_dict[arg_name] = arg_value
# END loop over action_args... # END loop over action_args...