diff options
| author | Lvov Maxim <usrleon@gmail.com> | 2011-06-09 22:02:01 +0400 |
|---|---|---|
| committer | Lvov Maxim <usrleon@gmail.com> | 2011-06-09 22:02:01 +0400 |
| commit | f53e7d16181e0a7141956d835f71c09d76508c2d (patch) | |
| tree | d88409575fe1b88e58c7eb25600374c4e988bf42 /bin | |
| parent | b85e089f807249eacc66172e56a1a69d450fafba (diff) | |
parse options with optparse, options prepended '--'
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/nova-manage | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/bin/nova-manage b/bin/nova-manage index 8faf072bc..76bed16f7 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -62,6 +62,8 @@ import sys import time import IPy +from inspect import getargspec +from optparse import OptionParser # 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... @@ -1133,14 +1135,18 @@ def main(): matches = lazy_match(action, actions) action, fn = matches[0] - fn_args, fn_kwargs = [], {} - for arg in argv: - if '=' in arg: - key, value = arg.split('=') - fn_kwargs[key] = value - else: - fn_args.append(arg) - + func_args = getargspec(fn).args + parser = OptionParser() + for arg in func_args: + dasharg = "--%s" % arg + parser.add_option(dasharg) + + (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 try: fn(*fn_args, **fn_kwargs) |
