Skip to content

Commit

Permalink
Merge pull request #776 from danielgtaylor/shorthand-unpack
Browse files Browse the repository at this point in the history
Cast to correct types for list-structure(list-scalar, scalar). Fixes #776.
  • Loading branch information
danielgtaylor committed May 14, 2014
2 parents 3c34ec7 + 30f591d commit 9de9d09
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
18 changes: 11 additions & 7 deletions awscli/argprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,10 @@ 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.
arg_types = {}
args = {}
for arg in param.members.members:
arg_types[arg.name] = arg.type
# Arg name -> arg object lookup
args[arg.name] = arg
parsed = []
for v in value:
parts = self._split_on_commas(v)
Expand All @@ -234,11 +235,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:
if current_key not in args:
raise ParamUnknownKeyError(param, current_key,
arg_types.keys())
elif arg_types[current_key] == 'list':
args.keys())
current_value = unpack_scalar_cli_arg(args[current_key],
current[1].strip())
if args[current_key].type == 'list':
current_parsed[current_key] = [current_value]
else:
current_parsed[current_key] = current_value
Expand All @@ -248,7 +250,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

0 comments on commit 9de9d09

Please sign in to comment.