diff options
author | Jan Cholasta <jcholast@redhat.com> | 2016-05-30 10:36:48 +0200 |
---|---|---|
committer | Jan Cholasta <jcholast@redhat.com> | 2016-06-03 09:00:34 +0200 |
commit | 98ede1b0e8c8473d6910fab2328dbc81d740945c (patch) | |
tree | 911f5f673e8f1a8096c8d57d3a3e9c95b405c7ac | |
parent | 4c7be74526bd89ed1b481f3a1ac4bb467ee0ea2c (diff) | |
download | freeipa-98ede1b0e8c8473d6910fab2328dbc81d740945c.tar.gz freeipa-98ede1b0e8c8473d6910fab2328dbc81d740945c.tar.xz freeipa-98ede1b0e8c8473d6910fab2328dbc81d740945c.zip |
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>
-rw-r--r-- | ipalib/cli.py | 4 | ||||
-rw-r--r-- | ipalib/parameters.py | 5 | ||||
-rwxr-xr-x | makeapi | 1 |
3 files changed, 7 insertions, 3 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py index 1897a3431..33e982ef9 100644 --- a/ipalib/cli.py +++ b/ipalib/cli.py @@ -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] diff --git a/ipalib/parameters.py b/ipalib/parameters.py index 0ff592a8d..f574456cf 100644 --- a/ipalib/parameters.py +++ b/ipalib/parameters.py @@ -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: @@ -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', |