Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cast to correct types for list-structure(list-scalar, scalar) #776

Merged
merged 2 commits into from
May 14, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions awscli/argprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,12 @@ def add_example_fn(self, arg_name, help_command, **kwargs):
def _list_scalar_list_parse(self, param, value):
# Think something like ec2.DescribeInstances.Filters.
# We're looking for key=val1,val2,val3,key2=val1,val2.
args = {}
arg_types = {}
for arg in param.members.members:
# Arg name -> arg object lookup
args[arg.name] = arg
# Arg name -> arg type lookup
arg_types[arg.name] = arg.type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need both args and arg_types. If we're storing the whole object could we just use args[name].type instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - I'll update it.

parsed = []
for v in value:
Expand All @@ -234,11 +238,12 @@ def _list_scalar_list_parse(self, param, value):
if len(current) == 2:
# This is a key/value pair.
current_key = current[0].strip()
current_value = current[1].strip()
if current_key not in arg_types:
raise ParamUnknownKeyError(param, current_key,
arg_types.keys())
elif arg_types[current_key] == 'list':
current_value = unpack_scalar_cli_arg(args[current_key],
current[1].strip())
if arg_types[current_key] == 'list':
current_parsed[current_key] = [current_value]
else:
current_parsed[current_key] = current_value
Expand All @@ -248,7 +253,9 @@ def _list_scalar_list_parse(self, param, value):
# ^
# |
# val2 is associated with key1.
current_parsed[current_key].append(current[0])
current_value = unpack_scalar_cli_arg(args[current_key],
current[0])
current_parsed[current_key].append(current_value)
else:
raise ParamSyntaxError(part)
parsed.append(current_parsed)
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/test_argprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,22 @@ def test_list_structure_list_scalar(self):
"Name = architecture, Values = i386"])
self.assertEqual(returned3, expected)

def test_list_structure_list_scalar_2(self):
p = self.get_param_object('emr.ModifyInstanceGroups.InstanceGroups')
expected = [
{"InstanceGroupId": "foo",
"InstanceCount": 4},
{"InstanceGroupId": "bar",
"InstanceCount": 1}
]

simplified = self.simplify(p, [
"InstanceGroupId=foo,InstanceCount=4",
"InstanceGroupId=bar,InstanceCount=1"
])

self.assertEqual(simplified, expected)

def test_list_structure_list_multiple_scalar(self):
p = self.get_param_object('elastictranscoder.CreateJob.Playlists')
returned = self.simplify(
Expand Down