diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-13 06:25:42 +0000 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-13 06:25:42 +0000 |
commit | 337c9964d42066368460da9a7c0d770142e2d1c3 (patch) | |
tree | 9b9b1fd8671c93464250b1e1e66dfc5eb72b2b36 /ipalib/cli.py | |
parent | 6924d5e25e237244e20554c380454a4029a0288f (diff) | |
download | freeipa-337c9964d42066368460da9a7c0d770142e2d1c3.tar.gz freeipa-337c9964d42066368460da9a7c0d770142e2d1c3.tar.xz freeipa-337c9964d42066368460da9a7c0d770142e2d1c3.zip |
145: Added new CLI.parse() method; added corresponding unit tests
Diffstat (limited to 'ipalib/cli.py')
-rw-r--r-- | ipalib/cli.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py index 6f0305d64..bf96d3698 100644 --- a/ipalib/cli.py +++ b/ipalib/cli.py @@ -97,7 +97,9 @@ class CLI(object): sys.exit(2) self.run_cmd(cmd, sys.argv[2:]) - def run_cmd(self, cmd, args): + def run_cmd(self, cmd, given): + print self.parse(given) + sys.exit(0) kw = dict(self.parse_kw(args)) self[cmd](**kw) @@ -110,6 +112,18 @@ class CLI(object): m.group(2), ) + def parse(self, given): + args = [] + kw = {} + for g in given: + m = re.match(r'^--([a-z][-a-z0-9]*)=(.+)$', g) + if m: + kw[from_cli(m.group(1))] = m.group(2) + else: + args.append(g) + return (args, kw) + + def __get_mcl(self): """ Returns the Max Command Length. |