114: Fixed cmd.__get_options(); more work on CLI

This commit is contained in:
Jason Gerard DeRose
2008-08-12 02:03:47 +00:00
parent 902614a762
commit bc4b26ffca
3 changed files with 31 additions and 10 deletions

View File

@@ -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()