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