Skip to content

Commit

Permalink
Support strings as bool values in shorthand syntax
Browse files Browse the repository at this point in the history
When using shorthand syntax, bool types are passed as
a string value, so we need to support "true" and "false".

This is fairly conservative in that, it's either exactly
"[Ff]alse", otherwise it's True.  We could require more
strict checking though if we want.
  • Loading branch information
jamesls committed Nov 7, 2013
1 parent 0211a4d commit 583b30f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ NEXT RELEASE (TBD)
* Log the reason why a file is synced when using the ``s3 sync`` command
* Fix an issue when uploading large files on low bandwidth networks
(issue 454)
* Fix an issue with parsing shorthand boolean argument values (issue 477)


1.2.3
Expand Down
2 changes: 2 additions & 0 deletions awscli/argprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ def unpack_scalar_cli_arg(parameter, value):
raise ValueError(msg)
return open(file_path, 'rb')
elif parameter.type == 'boolean':
if isinstance(value, str) and value.lower() == 'false':
return False
return bool(value)
else:
return str(value)
12 changes: 12 additions & 0 deletions tests/unit/test_argprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from tests import unittest

import botocore.session
import mock

from awscli.clidriver import CLIArgument
from awscli.help import OperationHelpCommand
Expand Down Expand Up @@ -107,6 +108,17 @@ def test_simplify_structure_scalars(self):
json_version = unpack_cli_arg(p, json_value)
self.assertEqual(returned, json_version)

def test_parse_boolean_shorthand(self):
bool_param = mock.Mock()
bool_param.type = 'boolean'
self.assertTrue(unpack_cli_arg(bool_param, True))
self.assertTrue(unpack_cli_arg(bool_param, 'True'))
self.assertTrue(unpack_cli_arg(bool_param, 'true'))

self.assertFalse(unpack_cli_arg(bool_param, False))
self.assertFalse(unpack_cli_arg(bool_param, 'False'))
self.assertFalse(unpack_cli_arg(bool_param, 'false'))

def test_simplify_map_scalar(self):
p = self.get_param_object('sqs.SetQueueAttributes.Attributes')
returned = self.simplify(p, 'VisibilityTimeout=15')
Expand Down

0 comments on commit 583b30f

Please sign in to comment.