
                             d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ dZ	dZ
d	Zd
ZdZdZddddddZd Zd Z G d dej$                        Zy)z%Custom printer for Cloud Run presets.    )absolute_import)division)unicode_literalsN)custom_printer_basepresets   &         P   Unspecified
QuickstartzAdd-onOptimization)KIND_UNSPECIFIEDCATEGORY_UNSPECIFIEDCATEGORY_QUICKSTARTCATEGORY_ADDONCATEGORY_OPTIMIZATIONc                 j    | sy| t         v r	t         |    S | j                  dd      j                         S )z+Formats a generic enum string into a title. _ )PRESETS_ENUM_MAPreplacetitle)enum_strings    >lib/googlecloudsdk/command_lib/run/printers/presets_printer.py_format_enumr   )   s8    	$$K((			S#	&	,	,	..    c                 8    | sydj                  d | D              S )z0Formats a list of kind enum strings for display.Nonez, c              3   2   K   | ]  }t        |        y w)N)r   ).0kinds     r   	<genexpr>z$_format_kind_list.<locals>.<genexpr>6   s     <)$<%)s   )join)	kind_lists    r   _format_kind_listr(   2   s    		<)<	<<r   c                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)
PresetsPrinterz<Prints a Cloud Run preset in a custom human-readable format.c                 ~   t        j                  t        j                  dg      | j                  |      t        j                  dg      | j                  |      t        j                  dg      | j	                  |      t        j                  dg      | j                  |      t        j                  dg      g	      S )z-Transforms a preset into a structured output.r   )cpLines_get_preset_info_get_preset_inputs_get_key_preset_config
_get_usage)selfpresets     r   	TransformzPresetsPrinter.Transform<   s    88
#f%
#'
###F+
#
#
 
 
r   c                 |   dt        |j                  dd            fdt        |j                  dd            fdt        |j                  dg             fdt        |j                  d	d            fd
t        |j                  dd            fg}g }|D ]  \  }}|s	t	        j
                  |t        t        z
        }|r|d   nd}|j                  |j                  t              |z          |dd D ]  }|j                  dt        z  |z            t        j                  t        j                  |      g      S )z Formats the preset info section.zName:namer   z	Category:categoryzApplies to:supported_resourceszDescription:descriptionzPreset Version:versionwidthr      Nr   )strgetr   r(   textwrapwrap
_MAX_WIDTH_INFO_INDENT_WIDTHappendljustr,   Sectionr-   )	r2   r3   fieldslineslabelvaluewrapped_lines
first_linelines	            r   r.   zPresetsPrinter._get_preset_infoJ   s,    
#fjj,-.	l6::j"#=>?fjj)>CD	
 
VZZr:;<	C

9b 9:;	F Eumm
z$66m (5=#"jll5;;12Z?@#$S--45 $  ::rxx'((r   c                     d|j                  t              z   dz   |j                  t              z   dz   |j                  t              z   S )z4Helper to format a single row with specific padding.z  r   )rE   _NAME_COL_WIDTH_DESC_COL_WIDTH_REQ_COL_WIDTH)r2   r6   descrequireds       r   _format_rowzPresetsPrinter._format_rowe   sU     	
**_
%	&
	 **_
%	& 		
 ..
(	)r   c           	      |    dd| j                  ddd      | j                  dt        z  dt        z  dt        z        gS )z1Returns the header for the preset inputs section.zInputs:r   NameDescriptionRequired-)rT   rO   rP   rQ   )r2   s    r   _get_preset_inputs_headerz(PresetsPrinter._get_preset_inputs_headerp   sJ     	
;/!3#8#:N	
	 r   c           	         |j                  dg       }|sy| j                         }|D ]  }|j                  dd      }|j                  dd      }|j                  dd      rdnd	}t        j                  |t        
      }|r|d   nd}	|j                  | j                  ||	|             |dd D ]$  }
|j                  | j                  d|
d             &  t        j                  t        j                  |      g      S )z"Formats the preset inputs section.
parametersNr6   r   r9   rS   FYesNor;   r   r=   )
r?   rZ   r@   rA   rP   rD   rT   r,   rF   r-   )r2   r3   r\   inputsparamr6   rR   rS   wrapped_descfirst_desc_linerM   s              r   r/   z!PresetsPrinter._get_preset_inputs{   s    L"-J++-FYYvr"dYY}b)d))J6Dh]]4?l+7QRommD$$T?HEFqr"$d&&r445 #  ::rxx'())r   c           
          |j                  di       }|syt        j                  |j                               }t        j                  t        j                  dt        j
                  d|dg      fg      g      S )z-Formats the key preset configuration section.config_valuesNzKey Preset Configurationr   )r?   r,   LabeleditemsrF   r-   )r2   r3   rd   labeled_datas       r   r0   z%PresetsPrinter._get_key_preset_config   sl    JJ3M::m1134L::


("((Cs3K*LMN	
  r   c                    |j                  dg       }|syt        |t              r|g}dg}|j                  |       |j	                  d       t        j                  t        j                  dt        j                  |      fg      g      S )z(Formats the preset gcloud usage section.example_gcloud_usageNr   Usage)	r?   
isinstancer>   extendrD   r,   rF   re   r-   )r2   r3   usage_linesfull_usage_strings       r   r1   zPresetsPrinter._get_usage   s    **3R8K+s# Mk[)S!::	grxx(9:;<	=> r   N)__name__
__module____qualname____doc__r4   r.   rT   rZ   r/   r0   r1    r   r   r*   r*   9   s(    D)6		*(
r   r*   )rr   
__future__r   r   r   r@   googlecloudsdk.core.resourcer   r,   PRESETS_PRINTER_FORMATrO   rP   rQ   rC   rB   r   r   r(   CustomPrinterBaser*   rs   r   r   <module>rx      sp    , &  '  B"  
 &)'+ /=pR)) pr   