
    >                         S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKJr  SSK	J
r
  SSK	Jr  SSKrSS	KJr  S
 r\" S5      u  rrrrrS rS rS rS rS rS rS rS rS rg)zCommon resource topic text.    )absolute_import)division)unicode_literalsN)api_lib)resource_printer)resource_transform)rangec           	      x   SnSSSSS.nX;  a1  [        SR                  SR                  [        U5      5      U S	95      e0 n[        R
                  " U5       H.  u  pEX@:X  a  S
R                  US9X4'   M  SR                  US9X4'   M0     [        R                  " U5      R                  US   US   US   US   S9$ )aJ  Generates resource help DESCRIPTION help text for name.

This puts common text for the key, formats and projections topics in one
place.

Args:
  name: One of ['filter', 'format', 'key', 'projection'].

Raises:
  ValueError: If name is not one of the expected topic names.

Returns:
  A detailed_help DESCRIPTION markdown string.
a    Most *gcloud* commands return a list of resources on success. By default they
  are pretty-printed on the standard output. The
  *--format=*_NAME_[_ATTRIBUTES_]*(*_PROJECTION_*)* and
  *--filter=*_EXPRESSION_ flags along with projections can be used to format and
  change the default output to a more meaningful result.

  Use the `--format` flag to change the default output format of a command.   {see_format}

  Use the `--filter` flag to select resources to be listed. {see_filter}

  Use resource-keys to reach resource items through a unique path of names from the root. {see_key}

  Use projections to list a subset of resource keys in a resource.   {see_projection}

  Note: To refer to a list of fields you can sort, filter, and format by for
  each resource, you can run a list command with the format set to `text` or
  `json`. For
  example, $ gcloud compute instances list --limit=1 --format=text.

  To work through an interactive tutorial about using the filter and format
  flags instead, see: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/cloud-shell-tutorials&page=editor&tutorial=cloudsdk/tutorial.md
  filtersformatszresource-keysprojections)filterformatkey
projectionz)Expected one of [{topics}], got [{name}].,)topicsnamez0Resource {topic}s are described in detail below.)topicz)For details run $ gcloud topic {command}.)commandr   r   r   r   )
see_filter
see_formatsee_keysee_projection)
ValueErrorr   joinsortedsix	iteritemstextwrapdedent)r   descriptionr   seer   r   s         3lib/googlecloudsdk/core/resource/resource_topics.pyResourceDescriptionr%   !   s    +6 !	& 

@GGxxv'd H 4 5 5
#f-ne}ELL M cj ?EE F cj . 
	%	,	,H8;H58Z<?<M 
- 
O O       c                     U (       aW  U S   R                  S5      (       d=  U S   R                  S5      (       a  U R                  S5        gU R                  S5        ggg)a  Appends paragraph markdown to lines.

Paragraph markdown is used to add paragraphs in nested lists at the list
prevaling indent. _AppendParagraph does not append the markdown if the last
line in lines is already a paragraph markdown.

A line containing only the + character is a paragraph markdown. It renders
a blank line and starts the next paragraph of lines using the prevailing
indent. A blank line would also start a new paragraph but would decrease the
prevailing indent.

Args:
  lines: The lines to append to.
z
+

z+
N)endswithappend)liness    r$   _AppendParagraphr.   d   sO     59%%g..Ry$ll5ll7 /Ur&   c                    U(       a  Sn[        U 5        O1U (       a*  U S   R                  S5      (       d  U R                  S5        UR                  S5      (       d  UR                  S5      (       aU  U (       a*  U S   R                  S5      (       d  U R                  S5        U R                  U5        U R                  S5        U$ U R                  U5        U$ )zAppends line to lines handling list markdown.

Args:
  lines: The lines to append to.
  line: The line to append.
  paragraph: Start a new paragraph if True.

Returns:
  The new paragraph value. This will always be False.
Fr)   r*    z* z::)r.   r+   r,   
startswith)r-   line	paragraphs      r$   _AppendLiner4   |   s     IUU2Y''--	LL	__TdmmD11U2Y''--ll4	LL	LL 
 
LL	r&   c                 j   / n/ n/ nU R                   (       d  gU R                   R                  S5      u    pE[        nSn/ nSn	[        R                  " U5      R                  S5       GH  n
U
R                  S5      (       dg  U
R                  S5      (       aQ  Sn	U(       a$  UR                  USR                  U5      45        SnU
S:X  a  [        nMk  U
S	:X  a  [        nMy  [        nM  U[        :X  a  M  U
(       d  S
n	M  U[        :X  a  [        XU	5      n	M  U
R                  S5      (       a(  U[        :X  a  [        XR                  5       U	5      n	M  M  U[        :X  a%  U
R                  S5      (       a  [        X:U	5      n	GM  U(       a"  UR                  USR                  U5      45        U
R                  S5      u  ptnUR                  5       nUR                  S5      nUR                  5       /nGM     U(       a"  UR                  USR                  U5      45        SR                  U5      X#4$ )a  Parses the doc string for printer.

Args:
  printer: The doc string will be parsed from this resource format printer.

Returns:
  A (description, attributes) tuple:
    description - The format description.
    attributes - A list of (name, description) tuples, one tuple for each
      format-specific attribute.

Example resource printer docstring parsed by this method:
  '''This line is skipped. Printer attributes and Example sections optional.

  These lines describe the format.
  Another description line.

  Printer attributes:
    attribute-1-name: The description for attribute-1-name.
    attribute-N-name: The description for attribute-N-name.

  Example:
    One or more example lines for the 'For example:' section.
  '''
) r6   r6   r*   NFr0   :r6   zPrinter attributes:Example:T      *)__doc__	partition	_DOC_MAINr    r!   splitr1   r+   r,   r   _DOC_ATTRIBUTES_DOC_EXAMPLE	_DOC_SKIPr4   striplstrip)printerdescriptions
attributesexample_doccollect	attributeattribute_descriptionr3   r2   texts               r$   _ParseFormatDocStringrO      s   4 ,*'	oo''-)!Q'))ooc"((.d??3DMM#$6$6i	9bgg.C&DEF		&	&!:	I	i	I	l)<i		 	 	O	# 5zz|YO	 
$ 
L	 T__T%:%:gY7i 
9bgg.C&DEF>>#.iD//#i""3'i#zz|nQ /R y"''*?"@AB		
	33r&   c            	         S/n [        [        R                  " [        R                  " 5       5      5       H  u  p[        U5      u  p4nU R                  SR                  XS95        U(       aV  [        U 5        U R                  S5        U H#  u  pcU R                  SR                  XcS95        M%     U R                  S5        U(       d  M  [        U 5        U R                  SR                  S	R                  U5      S
95        M     U R                  S5        [        [        R                  5      u  p4nU(       aJ  U R                  SR                  USS S95        U H#  u  pcU R                  SR                  XcS95        M%     U(       a8  [        U 5        U R                  SR                  S	R                  U5      S
95        U R                  S5        S	R                  U 5      $ )zBReturns help markdown for all registered resource printer formats.z0The formats and format specific attributes are:
z
*{name}*::
{description}
)r   r"   zThe format attributes are:

z*{attribute}*:::
{description}
)rL   r"   :::
For example:
+
{example}
r6   rH   ::
z
{description}:
+
Nr)   )r"   z*{attribute}*::
{description}
r*   )r   r   r   r   GetFormatRegistryrO   r,   r   r.   r   PrinterAttributes)rF   r   rE   r"   rG   rH   rL   s          r$   FormatRegistryDescriptionsrW      s    FF,	mm$6689;md'<W'E$KW7>> ? , -|$:;$.
 )?FF G : 	; %/ '"w|$8??'''" @ $ %;  f &;((&*"+7/66$ 7 & '",	<CC D 8 9 #- \"6==  > " #d		r&   c                     U R                  S5      (       a  U R                  S5      $ SnU R                  U5      (       a  U [        U5      S $ U $ )z6Returns string with Pythonic unused notation stripped.rI   unused_N)r1   rD   len)stringunuseds     r$   _StripUnusedNotationr]     sN    s==&v#f+,	-r&   c                    SnU R                   (       d  gU R                   R                  S5      u  p#n[        nSnU/n/ n/ n	/ n
Sn[        R                  " U5      R                  S5       GHm  nU(       d  SnM  US:X  a
  [        nSnM  US:X  a
  [        nSnM/  U[        :X  a  M;  U[        :X  a  [        X|U5      nMS  U[        :X  a$  UR                  S	5      (       a  [        XU5      nM  U[        :X  a'  UR                  S
5      (       a  [        XSS U5      nM  U(       a  [        U5      nU(       a'  Xa;  a"  U	R                  USR                  U
5      45        UR                  S5      (       d  UR                  S5      (       a	  [        nGM'  UR                  S5      u  pcnUR                  5       nUR!                  S5      nUR                  5       /n
GMp     SSKnUR%                  U 5      n['        UR(                  5      ['        UR*                  =(       d    / 5      -
  n/ n[-        UR(                  5       H  u  nnU(       a  [        U5      nUU;   a  M   UU-
  nUS:  a  UR*                  U   OSnUbh  [/        U5      R1                  SS5      nUR                  S5      (       a  USS nUS:X  a  SnOUS:X  a  SnUR                  SR3                  UUS95        M  UR                  U5        M     UR4                  (       a  UR                  UR4                  5        SR3                  SR                  U5      S9nSR                  U5      UX4$ )a#  Parses the doc string for func.

Args:
  func: The doc string will be parsed from this function.

Returns:
  A (description, prototype, args) tuple:
    description - The function description.
    prototype - The function prototype string.
    args - A list of (name, description) tuples, one tuple for each arg.

Example transform function docstring parsed by this method:
  '''Transform description. Example sections optional.

  These lines are skipped.
  Another skipped line.

  Args:
    r: The resource arg is always sepcified but omitted from the docs.
    arg-2-name[=default-2]: The description for arg-2-name.
    arg-N-name[=default-N]: The description for arg-N-name.
    kwargs: Omitted from the description.

  Example:
    One or more example lines for the 'For example:' section.
  '''
)kwargsr   r)r6   r6   r6   r6   r*   NFTzArgs:r8   r9   r:      r0   r7   r;   r   '"zu"   FalsefalseTruetruez{formal}={default_display})formaldefault_displayz({formals})z, )formalsr6   )r<   r=   r>   r    r!   r?   	_DOC_ARGSrA   rB   r4   r1   r]   r,   r   r+   rC   rD   inspectgetfullargspecrZ   argsdefaults	enumeratereprreplacer   varargs)funchidden_argsr"   rI   rJ   rK   argrF   rH   ro   arg_descriptionr3   r2   rN   rm   argspecdefault_index_startrk   formal_indexri   default_indexdefaultrj   	prototypes                           r$   _ParseTransformDocStringr     s   8 .+	..t4+#'#,'	$/)ooc"((.di	gi		gi	I		I	l)<i	I	$//&"9"9oY?i	L	 T__T%:%:gABx;i 
"3'	'S#((?345__S!!dmmC&8&8^^C(lcdIIKcJJsOcoK /P  ""4('GLL)C0@0@0FB,GG''5lF#F+f #66M1>!1Cg}-GW--c37o		#	#D	)	))!"-	G	#!f$ nn188 9 : ; nnV' 6( __NN7??#""499W+=">)			4	88r&   c           	      >   / n[        [        R                  " U 5      5       H  u  p#[        U5      u  pEpgU(       d  M  UR	                  SR                  X%US95        U(       aV  [        U5        UR	                  S5        U H4  u  pUR	                  SR                  XS95        UR	                  S5        M6     U(       a8  [        U5        UR	                  SR                  SR                  U5      S	95        UR	                  S
5        M     SR                  U5      $ )zGenerates resource transform help text markdown for transforms.

Args:
  transforms: The transform name=>method symbol table.

Returns:
  The resource transform help text markdown for transforms.
z%

*{name}*{prototype}::
{description})r   r~   r"   zThe arguments are:
+
z*```{arg}```*:::
{description}
)rw   r"   rQ   rR   r6   rS   rT   )r   r   r   r   r,   r   r.   r   )	
transformsrF   r   	transformr"   r~   ro   rH   rw   s	            r$   TransformsDescriptionsr     s    ,j 9:od,DY,O)KDBIIK J A B|$34"
#?FF G . 	/G$ # |$8??'''" @ $ %# ;$ 
	r&   c                     U S:X  a  [         R                  " 5       $ SnSR                  U S9n [        X!/S9n[	        X15      nU" 5       $ ! [
         a     gf = f)z=Returns the transforms for api if it has a transforms module.builtinGetTransformsz'googlecloudsdk.api_lib.{api}.transforms)api)fromlistN)r   r   r   
__import__getattrImportError)r   method_namemodule_pathmodulemethods        r$   _GetApiTransformsr     se    I++--+9@@S@I+m<FV)F8O	 s   A
 

AAc            	      n   / n [        [        R                  " [        R                  5       VVs/ s H  u  po(       d  M  UPM     snn5      nS/[        U5      -    H?  n[        U5      nU(       d  M  U R                  SR                  U[        U5      S95        MA     SR                  U 5      $ s  snnf )z=Returns help markdown for all registered resource transforms.r   z+
The {api} transform functions are:
{desc}
)r   descr6   )setpkgutiliter_modulesr   __path__r   r   r,   r   r   r   )rF   rI   r   apisr   r   s         r$   TransformRegistryDescriptionsr     s    ,	%2273C3CDMD
tDM
O$[6$<'c"3'Jz
:
A
A2:> B @A ( 
	 Ns   B1
 B1
)r<   
__future__r   r   r   r   r    googlecloudsdkr   googlecloudsdk.core.resourcer   r   r   	six.movesr	   r%   r>   rl   r@   rA   rB   r.   r4   rO   rW   r]   r   r   r   r    r&   r$   <module>r      sy     " &  '   " 9 ; 
 =O@ BGq >	9o|Y04O4d$Nn9b>r&   