
    	                         d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlmZ ddlm	Z	 ddl
mZ  G d	 d
ej                        Zy)z,A command that reads JSON data and lists it.    )absolute_import)division)unicode_literalsN)base)
exceptions)filesc                   &    e Zd ZdZed        Zd Zy)ListFromJsona  Read JSON data and list it on the standard output.

  *{command}* is a test harness for resource output formatting and filtering.
  It behaves like any other `gcloud ... list` command except that the resources
  are read from a JSON data file.

  The input JSON data is either a single resource object or a list of resource
  objects of the same type. The resources are printed on the standard output.
  The default output format is *json*.
  c                     t         j                  j                  |        | j                  dddd d       | j                  j                  d       | j                  j                  d        y )N	json_filez	JSON-FILE?zA file containing JSON data for a single resource or a list of resources of the same type. If omitted then the standard input is read.)metavarnargsdefaulthelpjson)r   URI_FLAGRemoveFromParseradd_argumentdisplay_info	AddFormatAddCacheUpdater)parsers    "lib/surface/meta/list_from_json.pyArgszListFromJson.Args*   sb    MM""6*
   !!&)
''-    c                    |j                   r5	 t        j                  t        j                  |j                               }|S 	 t        j                  t        j                        }|S # t        j
                  t        f$ r4}t        j                  dj                  |j                   |            d }~ww xY w# t        t        f$ r)}t        j                  dj                  |            d }~ww xY w)NzCannot read [{}]: {}z"Cannot read the standard input: {})r   r   loadsr   ReadFileContentsError
ValueErrorr   BadFileExceptionformatloadsysstdinIOError)selfargs	resourceses       r   RunzListFromJson.Run8   s    ~~>JJu55dnnEF	 <IIcii(	  kk:& >))"))$..!<> 	>> z" <))077:< 	<<s/   2A( #B8 (B5/B00B58C0$C++C0N)__name__
__module____qualname____doc__staticmethodr   r,    r   r   r
   r
      s     	 . .r   r
   )r0   
__future__r   r   r   r   r%   googlecloudsdk.callioper   r   googlecloudsdk.core.utilr   ListCommandr
   r2   r   r   <module>r7      s4     3 &  '  
 ( . *'4## 'r   