parameters: introduce cli_metavar keyword argument

Add new Param keyword argument cli_metavar to specify the stand-in for CLI
option arguments in command help text. Uppercase class name is used by
default.

https://fedorahosted.org/freeipa/ticket/4739

Reviewed-By: David Kupka <dkupka@redhat.com>
This commit is contained in:
Jan Cholasta 2016-05-30 10:36:48 +02:00
parent 4c7be74526
commit 98ede1b0e8
3 changed files with 7 additions and 3 deletions

View File

@ -1163,10 +1163,8 @@ class cli(backend.Executioner):
kw['action'] = 'store_false'
else:
kw['action'] = 'store_true'
elif isinstance(option, Enum):
kw['metavar'] = list(str(x) for x in option.values)
else:
kw['metavar'] = option.__class__.__name__.upper()
kw['metavar'] = option.cli_metavar
cli_name = to_cli(option.cli_name)
option_names = ['--%s' % cli_name]

View File

@ -413,6 +413,7 @@ class Param(ReadOnly):
('alwaysask', bool, False),
('sortorder', int, 2), # see finalize()
('option_group', unicode, None),
('cli_metavar', str, None),
# The 'default' kwarg gets appended in Param.__init__():
# ('default', self.type, None),
@ -503,6 +504,9 @@ class Param(ReadOnly):
if kw.get('cli_name') is None:
kw['cli_name'] = self.name
if kw.get('cli_metavar') is None:
kw['cli_metavar'] = self.__class__.__name__.upper()
if kw.get('label') is None:
kw['label'] = FixMe(self.name)
@ -1514,6 +1518,7 @@ class Enum(Param):
)
def __init__(self, name, *rules, **kw):
kw['cli_metavar'] = str([str(v) for v in kw.get('values', tuple())])
super(Enum, self).__init__(name, *rules, **kw)
for (i, v) in enumerate(self.values):
if type(v) not in self.allowed_types:

View File

@ -47,6 +47,7 @@ API_DOC_ERROR = 8
# attributes removed from Param.__kw dictionary
PARAM_IGNORED_KW_ATTRIBUTES = (
'attribute',
'cli_metavar',
'default_from',
'doc',
'exclude',