o .&a!%@sFddlZddlmZeeZdZGdddeZGdddeZ dS)N)CustomArgument.cs:eZdZdZ  d fdd ZeddZdd ZZS) FlattenedArgumenta) A custom argument which has been flattened from an existing structure. When added to the call params it is hydrated back into the structure. Supports both an object and a list of objects, in which case the flattened parameters will hydrate a list with a single object in it. Nc s8||_||_||_||_||_tt|j|||ddS)N)name help_textrequired)type _container _property_hydrate_hydrate_valuesuperr__init__) selfr containerproprrr hydrate hydrate_value __class__?/usr/lib/python3/dist-packages/awscli/customizations/flatten.pyr s zFlattenedArgument.__init__cCs|jSN)r )rrrr cli_type_name*szFlattenedArgument.cli_type_namecCs|jjj}|jj}|j}td|||durw|jdkr&| dk }n|jdvr0t |}n |jdvr9t |}|j rG| |||||dS||vrY|dkrUig||<ni||<|j ra| |}|dkro|||d|<dS||||<dSdS) a Hydrate the original structure with the value of this flattened argument. TODO: This does not hydrate nested structures (``XmlName1.XmlName2``)! To do this for now you must provide your own ``hydrate`` method. zHydrating {0}[{1}]Nbooleanfalse)integerlong)floatdoublelistr)r argument_modelrrr LOGdebugformatr lowerintrr r )r parametersvaluercli_typekeyrrr add_to_params.s.       zFlattenedArgument.add_to_params)rNNNN) __name__ __module__ __qualname____doc__rpropertyrr, __classcell__rrrrrs rc@s8eZdZdZddZddZddZdd Zd d Zd S) FlattenArgumentsa Flatten arguments for one or more commands for a particular service from a given configuration which maps service call parameters to flattened names. Takes in a configuration dict of the form:: { "command-cli-name": { "argument-cli-name": { "keep": False, "flatten": { "XmlName": { "name": "flattened-cli-name", "type": "Optional custom type", "required": "Optional custom required", "help_text": "Optional custom docs", "hydrate_value": Optional function to hydrate value, "hydrate": Optional function to hydrate }, ... } }, ... }, ... } The ``type``, ``required`` and ``help_text`` arguments are entirely optional and by default are pulled from the model. You should only set them if you wish to override the default values in the model. The ``keep`` argument determines whether the original command is still accessible vs. whether it is removed. It defaults to ``False`` if not present, which removes the original argument. The keys inside of ``flatten`` (e.g. ``XmlName`` above) can include nested references to structures via a colon. For example, ``XmlName1:XmlName2`` for the following structure:: { "XmlName1": { "XmlName2": ... } } The ``hydrate_value`` function takes in a value and should return a value. It is only called when the value is not ``None``. Example:: "hydrate_value": lambda (value): value.upper() The ``hydrate`` function takes in a list of existing parameters, the name of the container, its type, the name of the container key and its set value. For the example above, the container would be ``'argument-cli-name'``, the key would be ``'XmlName'`` and the value whatever the user passed in. Example:: def my_hydrate(params, container, cli_type, key, value): if container not in params: params[container] = {'default': 'values'} params[container][key] = value It's possible for ``cli_type`` to be ``list``, in which case you should ensure that a list of one or more objects is hydrated rather than a single object. cCs||_||_dSr)configs service_name)rr5r4rrrrs zFlattenArguments.__init__cCs,|j}|jD] }|d|||jqdS)z Register with a CLI instance, listening for events that build the argument table for operations in the configuration dict. zbuilding-argument-table.{0}.{1}N)r5r4registerr% flatten_args)rcliservice operationrrrr6s  zFlattenArguments.registerc Ks|j|jD]h\}}||}d}td|j|ddd|dD|dD]3\}} | } || d<|| d<||j |} | | || t d i| } | || d <|| d krbd }q/|spd |vsm|d sp||=qdS) NFz$Flattening {0} argument {1} into {2}z, cSsg|]\}}|dqS)rr).0kvrrr sz1FlattenArguments.flatten_args..flattenrrrTkeepr) r4ritemsr#r$r%joincopy_find_nested_argr"_merge_member_configr) rcommandargument_tablekwargsrargumentargument_from_table overwritten sub_argument new_configconfig_argnew_argrrrr7s4   zFlattenArguments.flatten_argscCsft|vr1td||tddD]}|jD] \}}||kr(|}nqtd|q|S)z Find and return a nested argument, if it exists. If no nested argument is requested then the original argument is returned. If the nested argument cannot be found, then a ValueError is raised. zFinding nested argument in {0}NzInvalid piece {0})SEPr#r$r%splitmembersrA ValueError)rrIrpiece member_namememberrrrrDsz!FlattenArguments._find_nested_argcCsj|jD]-\}}||tdkr2d|vr|j|d<d|vr&||jv|d<d|vr/|j|d<dSqdS)a4 Merges an existing config taken from the configuration dict with an existing member of an existing argument object. This pulls in attributes like ``required`` and ``help_text`` if they have not been overridden in the configuration dict. Modifies the config in-place. rQrrr N)rTrArSrR documentationrequired_members type_name)rrIrrNrWrXrrrrEs  z%FlattenArguments._merge_member_configN) r-r.r/r0rr6r7rDrErrrrr3WsA % r3) loggingawscli.argumentsr getLoggerr-r#rRrobjectr3rrrrs   ?