summaryrefslogtreecommitdiffstats
path: root/ipalib/cli.py
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2014-03-18 10:11:19 +0100
committerPetr Viktorin <pviktori@redhat.com>2014-03-21 12:49:21 +0100
commitffd9bb2d7c4d19dae8e1e9b8daac415d83012c8e (patch)
tree52bd40cacfd71c344ea7e741fb9f5e74c0ed3676 /ipalib/cli.py
parent84c401f7d605cde6d0ca1429a7fc4c2ef65a38e1 (diff)
downloadfreeipa-ffd9bb2d7c4d19dae8e1e9b8daac415d83012c8e.tar.gz
freeipa-ffd9bb2d7c4d19dae8e1e9b8daac415d83012c8e.tar.xz
freeipa-ffd9bb2d7c4d19dae8e1e9b8daac415d83012c8e.zip
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
Diffstat (limited to 'ipalib/cli.py')
-rw-r--r--ipalib/cli.py42
1 files changed, 28 insertions, 14 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py
index 19f27b17a..067d78089 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -1102,7 +1102,18 @@ class cli(backend.Executioner):
description=unicode(cmd.doc),
formatter=IPAHelpFormatter(),
)
+
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():
kw = dict(
dest=option.name,
@@ -1122,22 +1133,25 @@ class cli(backend.Executioner):
else:
kw['metavar'] = option.__class__.__name__.upper()
+ cli_name = to_cli(option.cli_name)
+ option_names = ['--%s' % cli_name]
if option.cli_short_name:
- o = optparse.make_option('-%s' % option.cli_short_name, '--%s' % to_cli(option.cli_name), **kw)
- else:
- o = optparse.make_option('--%s' % to_cli(option.cli_name), **kw)
-
- if option.option_group is not None:
- option_group = option_groups.get(option.option_group)
- if option_group is None:
- option_group = optparse.OptionGroup(parser,
- option.option_group)
- parser.add_option_group(option_group)
- option_groups[option.option_group] = option_group
-
- option_group.add_option(o)
+ 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:
- parser.add_option(o)
+ _get_option_group(option.option_group).add_option(opt)
+
+ if option.deprecated_cli_aliases:
+ new_kw = dict(kw)
+ new_kw['help'] = _('Same as --%s') % cli_name
+ if isinstance(option, Enum):
+ new_kw['metavar'] = 'VAL'
+ group = _get_option_group(unicode(_('Deprecated options')))
+ for alias in option.deprecated_cli_aliases:
+ name = '--%s' % alias
+ group.add_option(optparse.make_option(name, **new_kw))
for arg in cmd.args():
name = self.__get_arg_name(arg, format_name=False)