Allow to add comments to parameters (#175)

This commit is contained in:
Alexandre Aubin 2018-11-04 16:00:12 +01:00 committed by GitHub
parent 9f7ee73b09
commit 4b94bf6585
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -84,6 +84,25 @@ class _ExtraParameter(object):
return value
class CommentParameter(_ExtraParameter):
name = "comment"
skipped_iface = ['api']
def __call__(self, message, arg_name, arg_value):
return msignals.display(m18n.n(message))
@classmethod
def validate(klass, value, arg_name):
# Deprecated boolean or empty string
if isinstance(value, bool) or (isinstance(value, str) and not value):
logger.warning("expecting a string for extra parameter '%s' of "
"argument '%s'", klass.name, arg_name)
value = arg_name
elif not isinstance(value, str):
raise TypeError("parameter value must be a string, got %r"
% value)
return value
class AskParameter(_ExtraParameter):
"""
Ask for the argument value if possible and needed.
@ -215,8 +234,8 @@ The list of available extra parameters classes. It will keep to this list
order on argument parsing.
"""
extraparameters_list = [AskParameter, PasswordParameter, RequiredParameter,
PatternParameter]
extraparameters_list = [CommentParameter, AskParameter, PasswordParameter,
RequiredParameter, PatternParameter]
# Extra parameters argument Parser