o
    !d                     @   s   d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ dd	 Zd
d ZG dd deZG dd de	ZdS )    N)
xform_name)Stubber)ArgumentGenerator)CLIOperationCaller)OverrideRequiredArgsArgument)json_encoderc                 C   s   |  dt d S )Nzbuilding-argument-table)registeradd_generate_skeleton)cli r   Musr/lib/python3.10/site-packages/awscli/customizations/generatecliskeleton.pyregister_generate_cli_skeleton   s   r   c                 K   s$   d|vrt | |}|| d S d S )Noutfile)GenerateCliSkeletonArgumentZadd_to_arg_table)sessionoperation_modelargument_tablekwargsZgenerate_cli_skeleton_argumentr   r   r   r	      s   r	   c                       sT   e Zd ZdZddddddgdZ fdd	Z fd
dZ fddZdd Z  Z	S )r   zThis argument writes a generated JSON skeleton to stdout

    The argument, if present in the command line, will prevent the intended
    command from taking place. Instead, it will generate a JSON skeleton and
    print it to standard output.
    zgenerate-cli-skeletonaJ  Prints a JSON skeleton to standard output without sending an API request. If provided with no value or the value ``input``, prints a sample input JSON that can be used as an argument for ``--cli-input-json``. If provided with the value ``output``, it validates the command inputs and returns a sample output JSON for that command.?inputoutput)nameZ	help_textnargsconstchoicesc                    s   t t| | || _d S )N)superr   __init___operation_model)selfr   r   	__class__r   r   r   <   s   
z$GenerateCliSkeletonArgument.__init__c                    s"   | j d| j tt|   d S )Nzcalling-command.*)_sessionr   generate_json_skeletonr   r   _register_argument_action)r   r   r   r   r#   @   s   z5GenerateCliSkeletonArgument._register_argument_actionc                    sl   d| j  }||v r4||}z||d  dkrW d S W n	 ty$   Y nw tt| j||fi | d S d S )Nz--   r   )r   index
IndexErrorr   r   override_required_args)r   r   argsr   Zarg_nameZarg_locationr   r   r   r'   E   s    



z2GenerateCliSkeletonArgument.override_required_argsc                 K   s   t |dd rH|jdk}| j}|r"|jj}|j}t| j||||S t	 }	|j
}
|
d u r/i }n|	|
}tjtj|dtd tjd dS d S )Ngenerate_cli_skeletonr      )indentdefault
r   )getattrr)   r   service_modelservice_namer   StubbedCLIOperationCallerr!   Zinvoker   Zinput_shapegenerate_skeletonsysstdoutwritejsondumpsr   )r   Zcall_parametersZparsed_argsparsed_globalsr   Z
for_outputr   r0   operation_nameargument_generatorZoperation_input_shapeZskeletonr   r   r   r"   U   s.   

z2GenerateCliSkeletonArgument.generate_json_skeleton)
__name__
__module____qualname____doc__ZARG_DATAr   r#   r'   r"   __classcell__r   r   r   r   r   &   s    r   c                   @   s   e Zd ZdZdd ZdS )r1   zA stubbed CLIOperationCaller

    It generates a fake response and uses the response and provided parameters
    to make a stubbed client call for an operation command.
    c           
      C   s   t |}|jj|}i }|jrtdd}||j}t|}	|	|| t	||di |W  d    S 1 s:w   Y  d S )NT)Zuse_member_namesr   )
r   metar/   r   Zoutput_shaper   r2   r   Zadd_responser.   )
r   Zclientr9   
parametersr8   method_namer   Zfake_responser:   Zstubberr   r   r   _make_client_call{   s   

$z+StubbedCLIOperationCaller._make_client_callN)r;   r<   r=   r>   rC   r   r   r   r   r1   u   s    r1   )r6   r3   Zbotocorer   Zbotocore.stubr   Zbotocore.utilsr   Zawscli.clidriverr   Zawscli.customizations.argumentsr   Zawscli.utilsr   r   r	   r   r1   r   r   r   r   <module>   s   	O