mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2026-10-25 22:50:12 -05:00
114: Fixed cmd.__get_options(); more work on CLI
This commit is contained in:
1 parent
902614a762
commit
bc4b26ffca
3 files changed
+31
-10
No files matched your search
+17
-2
@@ -21,8 +21,9 @@
|
||||
Functionality for Command Line Inteface.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import re
|
||||
import sys
|
||||
import optparse
|
||||
|
||||
|
||||
def to_cli(name):
|
||||
@@ -43,6 +44,10 @@ def from_cli(cli_name):
|
||||
return cli_name.replace('-', '_')
|
||||
|
||||
|
||||
def _(arg):
|
||||
return arg
|
||||
|
||||
|
||||
class CLI(object):
|
||||
def __init__(self, api):
|
||||
self.__api = api
|
||||
@@ -74,4 +79,14 @@ class CLI(object):
|
||||
self.run_cmd(cmd)
|
||||
|
||||
def run_cmd(self, cmd):
|
||||
print self[cmd]
|
||||
(options, args) = self.build_parser(cmd)
|
||||
print options
|
||||
|
||||
def build_parser(self, cmd):
|
||||
parser = optparse.OptionParser()
|
||||
for option in self[cmd].options:
|
||||
parser.add_option('--%s' % to_cli(option.name),
|
||||
help=option.get_doc(_),
|
||||
)
|
||||
|
||||
(options, args) parser.parse_args()
|
||||
+10
-7
@@ -60,16 +60,19 @@ api.register(user_find)
|
||||
|
||||
|
||||
# Register some properties for the 'user' object:
|
||||
class user_firstname(public.prop):
|
||||
pass
|
||||
api.register(user_firstname)
|
||||
class user_givenname(public.prop):
|
||||
def get_doc(self, _):
|
||||
return _('user first name')
|
||||
api.register(user_givenname)
|
||||
|
||||
class user_lastname(public.prop):
|
||||
pass
|
||||
api.register(user_lastname)
|
||||
class user_sn(public.prop):
|
||||
def get_doc(self, _):
|
||||
return _('user last name')
|
||||
api.register(user_sn)
|
||||
|
||||
class user_login(public.prop):
|
||||
pass
|
||||
def get_doc(self, _):
|
||||
return _('user login')
|
||||
api.register(user_login)
|
||||
|
||||
|
||||
|
||||
+4
-1
@@ -45,6 +45,7 @@ class option(plugable.Plugin):
|
||||
"""
|
||||
|
||||
__public__ = frozenset((
|
||||
'get_doc',
|
||||
'normalize',
|
||||
'default',
|
||||
'validate',
|
||||
@@ -167,7 +168,9 @@ class cmd(plugable.Plugin):
|
||||
Returns the NameSpace containing the option proxy objects.
|
||||
"""
|
||||
if self.__options is None:
|
||||
self.__options = plugable.NameSpace(self.get_options())
|
||||
object.__setattr__(self, '_cmd__options',
|
||||
plugable.NameSpace(self.get_options()),
|
||||
)
|
||||
return self.__options
|
||||
options = property(__get_options)
|
||||
|
||||
|
||||
Reference in new issue
Block a user