
    .                         d 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
mZ dd	lmZ  G d
 de	j                        Zy)z-The gcloud datastore operations list command.    )absolute_import)division)unicode_literals)
operations)rewrite_backend)base)
properties)resource_projection_specc                   ,    e Zd ZdZed        Zd Zd Zy)Lista  List pending Cloud Datastore admin operations and their status.

  Filters are case-sensitive and have the following syntax:

    field = value [AND [field = value]] ...

  where `field` is one of `kind`, `namespace`, `type`, or `labels.[KEY]`, and
  `[KEY]` is a label key. `kind` and `namespace` may be `*` to query for
  operations on all kinds and/or all namespaces. `type` may be one of
  `export_entities` or `import_entities`.

  Only the logical `AND` operator is
  supported; space-separated items are treated as having an implicit `AND`
  operator.

  ## EXAMPLES

  To see the list of all operations, run:

    $ {command}

  To see the list of all export operations, run:

    $ {command} --filter='type:export_entities'

  To see the list of all export operations for kind 'MyKind', run:

    $ {command} --filter='type:export_entities AND kind:MyKind'

  To see the list of all operations with particular labels, run:

    $ {command} --filter='labels.run = daily'
  c                     t         j                  j                  | t        j                         t         j
                  j                  | t        j                         y)z Register flags for this command.N)r   PAGE_SIZE_FLAG
SetDefaultr   DEFAULT_PAGE_SIZE
LIMIT_FLAG)parsers    (lib/surface/datastore/operations/list.pyArgsz	List.Args?   s:     	""6:+G+GHOOvz'C'CD    c                     | j                  |j                  |      \  }}||_        t        j                  t        j
                  j                  j                  j                  d      |j                  |      S )NT)required)projectlimitoperation_filter)
_ConvertFilterfilterr   ListOperationsr	   VALUEScorer   Getr   )selfargsfrontend_filterbackend_filters       r   RunzList.RunE   sd    &*&9&9$++t&L#O^!DK$$!!&&..22D2Ajj') )r   c                     t        j                         }|j                         }t        j                  |j
                  |j                        }|j                  ||      S )aT  Translates user-provided filter spec into one our backend understands.

    Args:
      expression: a filter spec to translate
      args: the args namespace object
    Returns:
      A tuple of string filter specs. The first is the frontend spec for post
      filtering, the second is a spec that the Datastore Admin API understands.
    )symbolsaliases)defaults)r   OperationsRewriteBackendGetDisplayInfor
   ProjectionSpec
transformsr(   Rewrite)r!   
expressionr"   operation_rewrite_backenddisplay_infor)   s         r   r   zList._ConvertFilterN   sY     !0 H H J&&(L'66''1E1EGH$,,Z(,KKr   N)__name__
__module____qualname____doc__staticmethodr   r%   r    r   r   r   r      s)     D E E
)Lr   r   N)r5   
__future__r   r   r    googlecloudsdk.api_lib.datastorer   r   googlecloudsdk.callioper   googlecloudsdk.corer	   googlecloudsdk.core.resourcer
   ListCommandr   r7   r   r   <module>r>      s8    4 &  ' 7 < ( * A@L4 @Lr   