Merge "Make _fix_argv() somewhat compatible with Argparse action='append'"
This commit is contained in:
commit
f6804f6b0d
@ -19,6 +19,7 @@ import collections
|
||||
import copy
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import warnings
|
||||
|
||||
@ -146,7 +147,9 @@ def _fix_argv(argv):
|
||||
# over the place.
|
||||
processed = collections.defaultdict(list)
|
||||
for index in range(0, len(argv)):
|
||||
if argv[index].startswith('--'):
|
||||
# If the value starts with '--' and has '-' or '_' in it, then
|
||||
# it's worth looking at it
|
||||
if re.match('^--.*(_|-)+.*', argv[index]):
|
||||
split_args = argv[index].split('=')
|
||||
orig = split_args[0]
|
||||
new = orig.replace('_', '-')
|
||||
|
@ -702,6 +702,17 @@ class TestConfigArgparse(base.TestCase):
|
||||
self.assertEqual(cc.config['auth']['password'], 'pass')
|
||||
self.assertEqual(cc.config['auth']['auth_url'], 'auth-url')
|
||||
|
||||
def test_argparse_action_append_no_underscore(self):
|
||||
c = config.OpenStackConfig(config_files=[self.no_yaml],
|
||||
vendor_files=[self.no_yaml],
|
||||
secure_files=[self.no_yaml])
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--foo', action='append')
|
||||
argv = ['--foo', '1', '--foo', '2']
|
||||
c.register_argparse_arguments(parser, argv=argv)
|
||||
opts, _remain = parser.parse_known_args(argv)
|
||||
self.assertEqual(opts.foo, ['1', '2'])
|
||||
|
||||
def test_argparse_underscores_duplicate(self):
|
||||
c = config.OpenStackConfig(config_files=[self.no_yaml],
|
||||
vendor_files=[self.no_yaml],
|
||||
|
Loading…
Reference in New Issue
Block a user