o @&aI@sdZddlZddlmZddlmZddlmZddlm Z ddlm Z e dZ Gd d d e Zd d ZGd ddeZGdddeZGdddeZGdddeZGdddeZdS)aAbstractions for CLI arguments. This module contains abstractions for representing CLI arguments. This includes how the CLI argument parser is created, how arguments are serialized, and how arguments are bound (if at all) to operation arguments. The BaseCLIArgument is the interface for all arguments. This is the interface expected by objects that work with arguments. If you want to implement your own argument subclass, make sure it implements everything in BaseCLIArgument. Arguments generally fall into one of several categories: * global argument. These arguments may influence what the CLI does, but aren't part of the input parameters needed to make an API call. For example, the ``--region`` argument specifies which region to send the request to. The ``--output`` argument specifies how to display the response to the user. The ``--query`` argument specifies how to select specific elements from a response. * operation argument. These are arguments that influence the parameters we send to a service when making an API call. Some of these arguments are automatically created directly from introspecting the JSON service model. Sometimes customizations may provide a pseudo-argument that takes the user input and maps the input value to several API parameters. N) xform_name)first_non_none_response)unpack_cli_arg)SchemaTransformer)modelzawscli.argumentsc@s eZdZdS)UnknownArgumentErrorN)__name__ __module__ __qualname__r r 2/usr/lib/python3/dist-packages/awscli/arguments.pyr4srcCs(t}||}t|}|d}|S)N InputShape)r transformr ShapeResolverget_shape_by_name)schema transformer shapes_mapshape_resolver arg_shaper r r !create_argument_model_from_schema8s    rc@seZdZdZddZddZddZdd Zed d Z ed d Z eddZ eddZ eddZ eddZeddZeddZeddZeddZeddZe jd d Z ed!d"Zd#S)$BaseCLIArgumentzsInterface for CLI argument. This class represents the interface used for representing CLI arguments. cC ||_dSN_name)selfnamer r r __init__Ms zBaseCLIArgument.__init__cCs|||j<dS)aAdd this object to the argument_table. The ``argument_table`` represents the argument for the operation. This is called by the ``ServiceOperation`` object to create the arguments associated with the operation. :type argument_table: dict :param argument_table: The argument table. The key is the argument name, and the value is an object implementing this interface. N)r)rargument_tabler r r add_to_arg_tablePs z BaseCLIArgument.add_to_arg_tablecCdS)amAdd this object to the parser instance. This method is called by the associated ``ArgumentParser`` instance. This method should make the relevant calls to ``add_argument`` to add itself to the argparser. :type parser: ``argparse.ArgumentParser``. :param parser: The argument parser associated with the operation. Nr rparserr r r add_to_parser]s zBaseCLIArgument.add_to_parsercCr!)a Add this object to the parameters dict. This method is responsible for taking the value specified on the command line, and deciding how that corresponds to parameters used by the service/operation. :type parameters: dict :param parameters: The parameters dictionary that will be given to ``botocore``. This should match up to the parameters associated with the particular operation. :param value: The value associated with the CLI option. Nr r parametersvaluer r r add_to_paramsjszBaseCLIArgument.add_to_paramscC|jSrrrr r r r{zBaseCLIArgument.namecCs d|jSNz--rr*r r r cli_name zBaseCLIArgument.cli_namecCtd)N cli_type_nameNotImplementedErrorr*r r r r0zBaseCLIArgument.cli_type_namecCr/)Nrequiredr1r*r r r r4r3zBaseCLIArgument.requiredcCr/)N documentationr1r*r r r r5r3zBaseCLIArgument.documentationcCr/)Ncli_typer1r*r r r r6r3zBaseCLIArgument.cli_typecC|jddSN-_rreplacer*r r r py_namezBaseCLIArgument.py_namecCr!)zList valid choices for argument value. If this value is not None then this should return a list of valid values for the argument. Nr r*r r r choicesszBaseCLIArgument.choicescCr!)Nr r*r r r synopsiszBaseCLIArgument.synopsiscCr!NFr r*r r r positional_argrBzBaseCLIArgument.positional_argcCsdSrr r*r r r nargsrBzBaseCLIArgument.nargscCrrrrr'r r r rr.cCr!)aGet the group name associated with the argument. An argument can be part of a group. This property will return the name of that group. This base class has no default behavior for groups, code that consumes argument objects can use them for whatever purposes they like (documentation, mutually exclusive group validation, etc.). Nr r*r r r group_names zBaseCLIArgument.group_nameN)rr r __doc__rr r$r(propertyrr-r0r4r5r6r=r?rArDrEsetterrGr r r r rEs@              rc@seZdZdZ     d ddZddZed d Zd d Zed dZ e j ddZ eddZ eddZ eddZ eddZeddZeddZeddZeddZdS)!CustomArgumentad Represents a CLI argument that is configured from a dictionary. For example, the "top level" arguments used for the CLI (--region, --output) can use a CustomArgument argument, as these are described in the cli.json file as dictionaries. This class is also useful for plugins/customizations that want to add additional args. r@NFcCs||_||_||_||_||_||_||_||_| |_| |_ | |_ |dur'g}||_ ||_ | |_ d|_| dur;|} | |_|jdurN|jjdkrPd|_dSdSdS)Nlist+)r_help_dest_default_action _required_nargs_const_cli_type_name _group_name_positional_arg_choices _synopsis no_paramfileargument_model_create_scalar_argument_model type_name)rr help_textdestdefaultactionr4r?rEr0rGrDrZr[rAconstr r r rs2   zCustomArgument.__init__cCs |jdurdS|j}td|iS)Ntype)rSr0r)rr]r r r r\s  z,CustomArgument._create_scalar_argument_modelcCs|jr|jSd|jSr,)rWrr*r r r r-s zCustomArgument.cli_namecCs|j}i}|jdur|j|d<|jdur|j|d<|jdur#|j|d<|jr+|j|d<|jdur5|j|d<|jdur?|j|d<|jdurI|j|d<|j|fi|dS) X See the ``BaseCLIArgument.add_to_parser`` docs for more information. Nr_rar`r?r4rErb) r-rOrQrPrXrRrSrT add_argument)rr#r-kwargsr r r r$s"             zCustomArgument.add_to_parsercCs|jdurdS|jSrCrRr*r r r r4s zCustomArgument.requiredcCrrrgrFr r r r4"r.cCr)r)rNr*r r r r5&r+zCustomArgument.documentationcCs4|jdur|jS|jdvrdS|jdur|jjSdS)N store_true store_falsebooleanstring)rUrQr[r]r*r r r r0*s   zCustomArgument.cli_type_namecCst}|jdvr t}|S)Nrh)strrQbool)rr6r r r r67s zCustomArgument.cli_typecCr)r)rXr*r r r r?>r+zCustomArgument.choicescCr)rrVr*r r r rGBr+zCustomArgument.group_namecCr)r)rYr*r r r rAFr+zCustomArgument.synopsiscCr)r)rWr*r r r rDJr+zCustomArgument.positional_argcCr)r)rSr*r r r rENr+zCustomArgument.nargs)r@NNNNNNNNFFNr@N)rr r rHrr\rIr-r$r4rJr5r0r6r?rGrArDrEr r r r rKs@  $          rKc @seZdZdZeeeeeeeeeeed Z  dddZ e ddZ e d d Z e j d d Z e d d Zej dd Ze ddZe ddZddZddZddZddZddZdS) CLIArgumentzARepresents a CLI argument that maps to a service parameter. ) structuremap timestamprLrlfloatintegerlongrkdoubleblobFNcCs<||_|dur |}||_||_||_||_||_|j|_dS)a= :type name: str :param name: The name of the argument in "cli" form (e.g. ``min-instances``). :type argument_model: ``botocore.model.Shape`` :param argument_model: The shape object that models the argument. :type argument_model: ``botocore.model.OperationModel`` :param argument_model: The object that models the associated operation. :type event_emitter: ``botocore.hooks.BaseEventHooks`` :param event_emitter: The event emitter to use when emitting events. This class will emit events during parts of the argument parsing process. This event emitter is what is used to emit such events. :type is_required: boolean :param is_required: Indicates if this parameter is required or not. N)r_serialized_namer[rR_operation_model_event_emitterr5_documentation)rrr[operation_model event_emitter is_requiredserialized_namer r r rfs zCLIArgument.__init__cCr7r8r;r*r r r r=r>zCLIArgument.py_namecCr)rrgr*r r r r4r+zCLIArgument.requiredcCrrrgrFr r r r4r.cCr)rr|r*r r r r5r+zCLIArgument.documentationcCrrrrFr r r r5r.cCs|jjSr)r[r]r*r r r r0r3zCLIArgument.cli_type_namecCs|j|jjtSr)TYPE_MAPgetr[r]rmr*r r r r6szCLIArgument.cli_typecCs"|j}|j||j|j|jddS)rd)helprcr4N)r-rer5r6r4rr#r-r r r r$s zCLIArgument.add_to_parsercCs6|durdS||}td||j||||j<dS)Nz+Unpacked value of %r for parameter "%s": %r)_unpack_argumentLOGdebugr=ry)rr&r'unpackedr r r r(s zCLIArgument.add_to_paramscCsJ|jjj}t|jjd}|jd||f|j||d}|dur |St||S)Nr9zprocess-cli-arg.%s.%s)param cli_argumentr')rz service_model service_namerr_emit_first_responser[r)rr'roperation_nameoverrider r r rs  zCLIArgument._unpack_argumentcKs|jj|fi|Sr)r{emit)rrrfr r r _emitszCLIArgument._emitcKs|j|fi|}t|Sr)rr)rrrf responsesr r r rsz CLIArgument._emit_first_response)FN)rr r rHrmrtintrnrrrIr=r4rJr5r0r6r$r(rrrr r r r rpSsH '         rpc@seZdZddZdS) ListArgumentcCs |j}|j|d|j|jddS)N*)rErcr4)r-rer6r4rr r r r$s  zListArgument.add_to_parserN)rr r r$r r r r rs rcsLeZdZdZ   dfdd ZddZd d Zd d Zed dZ Z S)BooleanArgumenta_Represent a boolean CLI argument. A boolean parameter is specified without a value:: aws foo bar --enabled For cases where the boolean parameter is required we need to add two parameters:: aws foo bar --enabled aws foo bar --no-enabled We use the capabilities of the CLIArgument to help achieve this. FriNc sbtt|j|||||| dd|_||_|dur|j|_n||_|dur)|j|_n||_| |_ dS)N)r) superrr _mutex_grouprQr= _destinationrrVrP) rrr[r}r~rrar_rGr`r __class__r r rs    zBooleanArgument.__init__cCs|dur |||j<dSdSr)ryr%r r r r(szBooleanArgument.add_to_paramsc CsF|||j<d|j}|j||j|j|jd|j|j|jd}|||<dS)Nzno-%srj)rar_rGr)rrr[rzr{rrGry)rr negative_namenegative_versionr r r r s   z BooleanArgument.add_to_arg_tablecCs"|j|j|j|j|j|jddS)N)rrar`r_)rer-r5rQrPrr"r r r r$*s  zBooleanArgument.add_to_parsercCr)rror*r r r rG1r+zBooleanArgument.group_name)FriNNNN) rr r rHrr(r r$rIrG __classcell__r r rr rsr)rHloggingbotocorerbotocore.hooksrawscli.argprocessr awscli.schemarr getLoggerr ExceptionrrobjectrrKrprrr r r r s"        |