parse options with optparse, options prepended '--'
This commit is contained in:
@@ -62,6 +62,8 @@ import sys
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
import IPy
|
import IPy
|
||||||
|
from inspect import getargspec
|
||||||
|
from optparse import OptionParser
|
||||||
|
|
||||||
# If ../nova/__init__.py exists, add ../ to Python search path, so that
|
# If ../nova/__init__.py exists, add ../ to Python search path, so that
|
||||||
# it will override what happens to be installed in /usr/(local/)lib/python...
|
# it will override what happens to be installed in /usr/(local/)lib/python...
|
||||||
@@ -1133,14 +1135,18 @@ def main():
|
|||||||
matches = lazy_match(action, actions)
|
matches = lazy_match(action, actions)
|
||||||
action, fn = matches[0]
|
action, fn = matches[0]
|
||||||
|
|
||||||
fn_args, fn_kwargs = [], {}
|
func_args = getargspec(fn).args
|
||||||
for arg in argv:
|
parser = OptionParser()
|
||||||
if '=' in arg:
|
for arg in func_args:
|
||||||
key, value = arg.split('=')
|
dasharg = "--%s" % arg
|
||||||
fn_kwargs[key] = value
|
parser.add_option(dasharg)
|
||||||
else:
|
|
||||||
fn_args.append(arg)
|
(opts, fn_args) = parser.parse_args(argv)
|
||||||
|
fn_kwargs = vars(opts)
|
||||||
|
for k, v in fn_kwargs.items():
|
||||||
|
if v is None:
|
||||||
|
del fn_kwargs[k]
|
||||||
|
|
||||||
# call the action with the remaining arguments
|
# call the action with the remaining arguments
|
||||||
try:
|
try:
|
||||||
fn(*fn_args, **fn_kwargs)
|
fn(*fn_args, **fn_kwargs)
|
||||||
|
|||||||
Reference in New Issue
Block a user