mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
cli: Add mechanism for deprecated option name aliases
Add a new Param kwarg, deprecated_cli_aliases, that lists deprecated aliases. The aliases will appear in a "Deprecated options" in the help, and otherwise act as the normal variant. Preparation for: https://fedorahosted.org/freeipa/ticket/4231
This commit is contained in:
parent
84c401f7d6
commit
ffd9bb2d7c
@ -1102,7 +1102,18 @@ class cli(backend.Executioner):
|
|||||||
description=unicode(cmd.doc),
|
description=unicode(cmd.doc),
|
||||||
formatter=IPAHelpFormatter(),
|
formatter=IPAHelpFormatter(),
|
||||||
)
|
)
|
||||||
|
|
||||||
option_groups = {}
|
option_groups = {}
|
||||||
|
|
||||||
|
def _get_option_group(group_name):
|
||||||
|
"""Get or create an option group for the given name"""
|
||||||
|
option_group = option_groups.get(group_name)
|
||||||
|
if option_group is None:
|
||||||
|
option_group = optparse.OptionGroup(parser, group_name)
|
||||||
|
parser.add_option_group(option_group)
|
||||||
|
option_groups[group_name] = option_group
|
||||||
|
return option_group
|
||||||
|
|
||||||
for option in cmd.options():
|
for option in cmd.options():
|
||||||
kw = dict(
|
kw = dict(
|
||||||
dest=option.name,
|
dest=option.name,
|
||||||
@ -1122,22 +1133,25 @@ class cli(backend.Executioner):
|
|||||||
else:
|
else:
|
||||||
kw['metavar'] = option.__class__.__name__.upper()
|
kw['metavar'] = option.__class__.__name__.upper()
|
||||||
|
|
||||||
|
cli_name = to_cli(option.cli_name)
|
||||||
|
option_names = ['--%s' % cli_name]
|
||||||
if option.cli_short_name:
|
if option.cli_short_name:
|
||||||
o = optparse.make_option('-%s' % option.cli_short_name, '--%s' % to_cli(option.cli_name), **kw)
|
option_names.append('-%s' % option.cli_short_name)
|
||||||
|
opt = optparse.make_option(*option_names, **kw)
|
||||||
|
if option.option_group is None:
|
||||||
|
parser.add_option(opt)
|
||||||
else:
|
else:
|
||||||
o = optparse.make_option('--%s' % to_cli(option.cli_name), **kw)
|
_get_option_group(option.option_group).add_option(opt)
|
||||||
|
|
||||||
if option.option_group is not None:
|
if option.deprecated_cli_aliases:
|
||||||
option_group = option_groups.get(option.option_group)
|
new_kw = dict(kw)
|
||||||
if option_group is None:
|
new_kw['help'] = _('Same as --%s') % cli_name
|
||||||
option_group = optparse.OptionGroup(parser,
|
if isinstance(option, Enum):
|
||||||
option.option_group)
|
new_kw['metavar'] = 'VAL'
|
||||||
parser.add_option_group(option_group)
|
group = _get_option_group(unicode(_('Deprecated options')))
|
||||||
option_groups[option.option_group] = option_group
|
for alias in option.deprecated_cli_aliases:
|
||||||
|
name = '--%s' % alias
|
||||||
option_group.add_option(o)
|
group.add_option(optparse.make_option(name, **new_kw))
|
||||||
else:
|
|
||||||
parser.add_option(o)
|
|
||||||
|
|
||||||
for arg in cmd.args():
|
for arg in cmd.args():
|
||||||
name = self.__get_arg_name(arg, format_name=False)
|
name = self.__get_arg_name(arg, format_name=False)
|
||||||
|
@ -300,6 +300,7 @@ class Param(ReadOnly):
|
|||||||
|
|
||||||
- cli_name: option name in CLI
|
- cli_name: option name in CLI
|
||||||
- cli_short_name: one character version of cli_name
|
- cli_short_name: one character version of cli_name
|
||||||
|
- deprecated_cli_aliases: deprecated CLI aliases
|
||||||
- label: very short description of the parameter. This value is used in
|
- label: very short description of the parameter. This value is used in
|
||||||
when the Command output is printed to CLI or in a Command help
|
when the Command output is printed to CLI or in a Command help
|
||||||
- doc: parameter long description used in help
|
- doc: parameter long description used in help
|
||||||
@ -384,6 +385,7 @@ class Param(ReadOnly):
|
|||||||
kwargs = (
|
kwargs = (
|
||||||
('cli_name', str, None),
|
('cli_name', str, None),
|
||||||
('cli_short_name', str, None),
|
('cli_short_name', str, None),
|
||||||
|
('deprecated_cli_aliases', frozenset, frozenset()),
|
||||||
('label', (basestring, Gettext), None),
|
('label', (basestring, Gettext), None),
|
||||||
('doc', (basestring, Gettext), None),
|
('doc', (basestring, Gettext), None),
|
||||||
('required', bool, True),
|
('required', bool, True),
|
||||||
|
Loading…
Reference in New Issue
Block a user