
                             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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Z G d dej"                        Zy)zAA command that parses resources given collection and api version.    )absolute_import)division)unicode_literalsN)base)
exceptions)log)	resources)
console_io)resource_printerc                   .    e Zd ZdZed        Zd ZddZy)ParsezCloud SDK resource parser module tester.

  *{command}* is an handy way to debug the resource parser from the command
  line.
  c                     | j                  ddd       | j                  ddd       | j                  dd	d
d       | j                  ddd       y )Nz--api-versionVERSIONzUThe resource collection API version. The collection default is used if not specified.)metavarhelpz--collectionNAMEz6The resource collection name of the resource to parse.z--stack-trace
store_trueTzGEnable all exception stack traces, including Cloud SDK core exceptions.)actiondefaultr   resources_to_parse*z~The list of resource URLs to parse. If not specified then *{command}* enters an interactive loop, prompting for URLs to parse.)nargsr   )add_argument)parsers    #lib/surface/meta/resources/parse.pyArgsz
Parse.Args)   s    
*  ,
 E  G 	         c           	         |j                   rI|j                  j                  d      d   }t        j                  j                  ||j                          |j                  rg }|j                  D ]  }	 t        j                  j                  ||j                        }|j%                         }|j#                  |j&                  |j                   |j(                  |j+                         |j-                         d        |S 	 t/        j0                  d      }|nT|s	 t        j                  j                  ||j                        j+                         }t3        j4                  |d	       lt6        j8                  j;                  d
       y# t        t        f$ r{}|j                  rt        j                  |       t        j                  t        j                   |             |j#                  t        j                   |      |d       Y d}~d}~ww xY w# t        t        f$ rT}|j                  rt        j                  |       t        j                  t        j                   |             Y d}~xd}~ww xY w)z/Returns the parsed parameters for one resource..r   )api_version)
collection)erroruriN)api_namer    r!   paramsr#   zPARSE> json
)r    r!   splitr	   REGISTRYRegisterApiByNamer   r   	Exception
SystemExitstack_tracer   reraiser   r"   six	text_typeappendGetCollectionInfor$   	full_nameAsDictSelfLinkr
   PromptResponser   Printsysstderrwrite)	selfargsr$   parsed_resourcesr#   resourceecollection_infor%   s	            r   Runz	Parse.RunA   s   &&s+A.h**
 0 0 + 2 ((#
	''--cdoo-N( #446'00*66)33oo'$$&!
 	 )( 
%%i0c	##)) * ((. 	 VV,   JJTI :& 	q!
))CMM!$
%

!
!}}Q'#  	: $ 


Q
		#--"#	s2   4+F!9H H A0HHJ-A	I<<Jc                      ~y )N )r;   items_were_listeds     r   EpilogzParse.Epilogs   s    r   N)F)__name__
__module____qualname____doc__staticmethodr   rA   rE   rC   r   r   r   r   "   s&      .0dr   r   )rI   
__future__r   r   r   r8   googlecloudsdk.callioper   googlecloudsdk.corer   r   r	   googlecloudsdk.core.consoler
   googlecloudsdk.core.resourcer   r/   ListCommandr   rC   r   r   <module>rQ      s@     H &  ' 
 ( * # ) 2 9 
RD Rr   