diff options
author | Rob Crittenden <rcritten@redhat.com> | 2009-06-10 15:07:24 -0400 |
---|---|---|
committer | Rob Crittenden <rcritten@redhat.com> | 2009-07-10 16:46:34 -0400 |
commit | d6e1e15fcd6eb924320fdb8f3d8138aba9eae0c3 (patch) | |
tree | e4c829ed8d411b2cd338686b0c0fa7ee7aac7fc0 | |
parent | c21e003cdfcda7915dc183aaab121be265185fd1 (diff) | |
download | freeipa-d6e1e15fcd6eb924320fdb8f3d8138aba9eae0c3.tar.gz freeipa-d6e1e15fcd6eb924320fdb8f3d8138aba9eae0c3.tar.xz freeipa-d6e1e15fcd6eb924320fdb8f3d8138aba9eae0c3.zip |
Add a one-character option for parameters
-rw-r--r-- | ipalib/cli.py | 5 | ||||
-rw-r--r-- | ipalib/parameters.py | 8 |
2 files changed, 12 insertions, 1 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py index 1a1673e41..d10523702 100644 --- a/ipalib/cli.py +++ b/ipalib/cli.py @@ -739,7 +739,10 @@ class cli(backend.Executioner): kw['action'] = 'store_true' else: kw['metavar'] = metavar=option.__class__.__name__.upper() - o = optparse.make_option('--%s' % to_cli(option.cli_name), **kw) + 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) parser.add_option(o) return parser diff --git a/ipalib/parameters.py b/ipalib/parameters.py index e805172a1..d9e33f8ad 100644 --- a/ipalib/parameters.py +++ b/ipalib/parameters.py @@ -221,6 +221,7 @@ class Param(ReadOnly): kwargs = ( ('cli_name', str, None), + ('cli_short_name', str, None), ('label', callable, None), ('doc', str, ''), ('required', bool, True), @@ -260,6 +261,13 @@ class Param(ReadOnly): self.name = check_name(name) self.nice = '%s(%r)' % (self.__class__.__name__, self.param_spec) + if 'cli_short_name' in kw: + if len(kw['cli_short_name']) != 1: + raise TypeError( + '%s: cli_short_name can only be a single character: %s' + % (self.nice, kw['cli_short_name']) + ) + # Add 'default' to self.kwargs and makes sure no unknown kw were given: assert type(self.type) is type if kw.get('multivalue', True): |