(argument_model, value, cli_name='')
| 215 | |
| 216 | |
| 217 | def unpack_scalar_cli_arg(argument_model, value, cli_name=''): |
| 218 | # Note the cli_name is used strictly for error reporting. It's |
| 219 | # not required to use unpack_scalar_cli_arg |
| 220 | if ( |
| 221 | argument_model.type_name == 'integer' |
| 222 | or argument_model.type_name == 'long' |
| 223 | ): |
| 224 | return int(value) |
| 225 | elif ( |
| 226 | argument_model.type_name == 'float' |
| 227 | or argument_model.type_name == 'double' |
| 228 | ): |
| 229 | # TODO: losing precision on double types |
| 230 | return float(value) |
| 231 | elif ( |
| 232 | argument_model.type_name == 'blob' |
| 233 | and argument_model.serialization.get('streaming') |
| 234 | ): |
| 235 | file_path = os.path.expandvars(value) |
| 236 | file_path = os.path.expanduser(file_path) |
| 237 | if not os.path.isfile(file_path): |
| 238 | msg = 'Blob values must be a path to a file.' |
| 239 | raise ParamError(cli_name, msg) |
| 240 | return open(file_path, 'rb') |
| 241 | elif argument_model.type_name == 'boolean': |
| 242 | if isinstance(value, str) and value.lower() == 'false': |
| 243 | return False |
| 244 | return bool(value) |
| 245 | else: |
| 246 | return value |
| 247 | |
| 248 | |
| 249 | def _supports_shorthand_syntax(model): |
no test coverage detected