
    z                     .   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Jr  SS
KJr  SSKJr  SSKJr  SSSS.r " S S\R(                  5      r " S S\5      r " S S\5      r " S S\5      r " S S\\R2                  S9r " S S\5      r " S S\5      r " S S\5      r " S  S!\5      rS" r\" SS#\	R@                  " S$5      \	RB                  " \RD                  RF                  RH                  5      /S%9r%S\%0r&S\%0r'g)&a  Classes to specify concept and resource specs.

Concept specs hold information about concepts. "Concepts" are any entity that
has multiple attributes, which can be specified via multiple flags on the
command line. A single concept spec should be created and re-used for the same
concept everywhere it appears.

Resource specs (currently the only type of concept spec used in gcloud) hold
information about a Cloud resource. "Resources" are types of concepts that
correspond to Cloud resources specified by a collection path, such as
'example.projects.shelves.books'. Their attributes correspond to the parameters
of their collection path. As with concept specs, a single resource spec
should be defined and re-used for each collection.

For resources, attributes can be configured by ResourceParameterAttributeConfigs
using kwargs. In many cases, users should also be able to reuse configs for the
same attribute across several resources (for example,
'example.projects.shelves.books.pages' could also use the shelf and project
attribute configs).
    )absolute_import)division)unicode_literalsN)deps)deps_map_util)util)yaml_command_schema_util)
exceptions)
properties)	resourcesproject)r   	projectId
projectsIdc                       \ rS rSrSrSrg)Error<   z%Base class for errors in this module. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       0lib/googlecloudsdk/calliope/concepts/concepts.pyr   r   <       -r   r   c                       \ rS rSrSrSrg)InitializationError@   z%Raised if a spec fails to initialize.r   Nr   r   r   r   r   r   @   r   r   r   c                       \ rS rSrSrSrg)ResourceConfigurationErrorD   z,Raised if a resource is improperly declared.r   Nr   r   r   r   r"   r"   D   s    4r   r"   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )InvalidResourceArgumentListsH   z8Exception for missing, extra, or out of order arguments.c                    > U Vs/ s H  o3[         ;   a  SU-   S-   OUPM     nn[        [        U ]  SR	                  SR                  U5      SR                  U5      5      5        g s  snf )N[]z6Invalid resource arguments: Expected [{}], Found [{}]., )IGNORED_FIELDSsuperr%   __init__formatjoin)selfexpectedactuale	__class__s       r   r-   %InvalidResourceArgumentLists.__init__K   sd    EMNXn!4a#!;XHN	
&6@GGIIh6!2	45 Os   A'r   )r   r   r   r   r   r-   r   __classcell__r4   s   @r   r%   r%   H   s    @5 5r   r%   c                   >   \ rS rSrSr\\R                  S 5       5       r\\R                  S 5       5       r	\R                  S 5       r
\R                  S 5       r\R                  SS j5       r\R                   SS	 j5       r\R                  S
 5       rS rS rSrg)ConceptSpecR   zBase class for concept args.c                     g)zLA list of Attribute objects representing the attributes of the concept.
    Nr   r0   s    r   
attributesConceptSpec.attributesU       r   c                     g)z The name of the overall concept.Nr   r<   s    r   nameConceptSpec.name[   r?   r   c                     g)z'Returns True if attribute is an anchor.Nr   r0   	attributes     r   IsAnchorConceptSpec.IsAnchor`   r?   r   c                     g)z+Returns True if attribute is a leaf anchor.Nr   rD   s     r   IsLeafAnchorConceptSpec.IsLeafAnchord   r?   r   Nc                     g)z;Initializes the concept using fallthroughs and parsed args.Nr   )r0   fallthroughs_mapparsed_argss      r   
InitializeConceptSpec.Initializeh   r?   r   c                     g)z#Lazy parsing function for resource.Nr   r0   attribute_to_args_mapbase_fallthroughs_maprM   pluralallow_emptys         r   ParseConceptSpec.Parsel   r?   r   c                     g)z/Builds list of fallthroughs for each attribute.Nr   )r0   rR   rS   s      r   BuildFullFallthroughsMap$ConceptSpec.BuildFullFallthroughsMapq   r?   r   c                     [        U[        U 5      5      (       d  gU R                  UR                  :H  =(       a    U R                  UR                  :H  $ )NF)
isinstancetyperA   r=   r0   others     r   __eq__ConceptSpec.__eq__v   s=    eT$Z((YY%**$LE<L<L)LLr   c                 X    [        U R                  5      [        U R                  5      -   $ N)hashrA   r=   r<   s    r   __hash__ConceptSpec.__hash__|   s    		?T$//222r   r   rc   NFF)r   r   r   r   r   propertyabcabstractmethodr=   rA   rF   rI   rN   rV   rY   r`   re   r   r   r   r   r9   r9   R   s    $   +  + 2 2 6 6 F F 8=. . : :M3r   r9   )	metaclassc                   2    \ rS rSrSr  SS jrS rS rSrg)	
_Attribute   a  A base class for concept attributes.

Attributes:
  name: The name of the attribute. Used primarily to control the arg or flag
    name corresponding to the attribute. Must be in all lower case.
  param_name: corresponds to where the attribute is mapped in the resource
  help_text: String describing the attribute's relationship to the concept,
    used to generate help for an attribute flag.
  required: True if the attribute is required.
  fallthroughs: [googlecloudsdk.calliope.concepts.deps_lib.Fallthrough], the
    list of sources of data, in priority order, that can provide a value for
    the attribute if not given on the command line. These should only be
    sources inherent to the attribute, such as associated properties, not
    command-specific sources.
  completer: core.cache.completion_cache.Completer, the completer associated
    with the attribute.
  value_type: the type to be accepted by the attribute arg. Defaults to str.
Nc                 @   [         R                  " SU5      (       a6  [         R                  " SU5      (       a  [        SR                  U5      5      eXl        U=(       d    UU l        X0l        X@l        U=(       d    / U l        X`l	        U=(       d    [        U l        g)Initializes.z[A-Z]zr[a-z]z~Invalid attribute name [{}]: Attribute names should be in lower snake case (foo_bar) so they can be transformed to flag names.N)research
ValueErrorr.   rA   
param_name	help_textrequiredfallthroughs	completerstr
value_type)r0   rA   rt   ru   rv   rw   rx   rz   s           r   r-   _Attribute.__init__   s|    
 
yy4  RYYx%>%>K6$<  I (DDONM$*DN 'CDOr   c                    [        U[        U 5      5      (       d  gU R                  UR                  :H  =(       a    U R                  UR                  :H  =(       a    U R                  UR                  :H  =(       ay    U R
                  UR
                  :H  =(       aY    U R                  UR                  :H  =(       a9    U R                  UR                  :H  =(       a    U R                  UR                  :H  $ )
Overrides.F)	r\   r]   rA   rt   ru   rv   rx   rw   rz   r^   s     r   r`   _Attribute.__eq__   s    eT$Z((II# 45;K;K(K 4%//14/4 %//14 !!U%7%77	4
 5#3#335r   c                     [        [        [        U R                  U R                  U R
                  U R                  U R                  U R                  /5      5      [        [        [        U R                  5      5      -   $ rc   )
summaprd   rA   rt   ru   rv   rx   rz   rw   r<   s    r   re   _Attribute.__hash__   s_    s4		4??DNNDMM) * +-0T4;L;L1M-NO Or   )rx   rw   ru   rA   rt   rv   rz   )NFNNN)	r   r   r   r   r   r-   r`   re   r   r   r   r   rm   rm      s!    & AF=A($	5Or   rm   c                   L   ^  \ rS rSrSr  SU 4S jjrU 4S jrU 4S jrSrU =r	$ )	Attribute   ay  An attribute of a resource.

Has all attributes of the base class along with resource-specific attributes.

Attributes:
  completion_request_params: {str: str}, a dict of field names to params to
    use as static field values in any request to complete this resource.
  completion_id_field: str, the ID field of the return value in the
      response for completion requests.
c                 \   > U=(       d    0 U l         X0l        [        [        U ]  " U40 UD6  g)rp   N)completion_request_paramscompletion_id_fieldr,   r   r-   )r0   rA   r   r   kwargsr4   s        r   r-   Attribute.__init__   s,     &?%D"D"2	)T#D3F3r   c                    > [         [        U ]  U5      =(       aY    U R                  UR                  :H  =(       a9    U R                  UR                  :H  =(       a    U R
                  UR
                  :H  $ )r}   )r,   r   r`   rx   r   r   r0   r_   r4   s     r   r`   Attribute.__eq__   sg    )T)%0 F%//1F..../F ((E,E,EE	Gr   c           
         > [         [        U ]  5       [        [	        [
        [        U R                  5      [        U R                  5      U R                  /5      5      -   $ rc   )
r,   r   re   r   r   rd   ry   rx   r   r   r0   r4   s    r   re   Attribute.__hash__   sR    D*,sD3t~~&t556++- 	.0/ / /r   )r   r   NN)
r   r   r   r   r   r-   r`   re   r   r6   r7   s   @r   r   r      s%    	 6:#'4G/ /r   r   c                      ^  \ rS rSrSrSr\SS j5       rSS\SS4S jr\	S 5       r
\	S	 5       r\	S
 5       rS rS r\	S 5       r\	S 5       rS rS rSS jr SS jr SS jr SS jr SS jr SS jr  SS jrU 4S jrU 4S jrSrU =r$ ) ResourceSpec   zIDefines a Cloud resource as a set of attributes for argument creation.
  TNc           
      d   SSK Jn  UR                  US   US9n[        UR	                  S5      UR
                  5      nU " S
UR                  US   UR                  UR	                  S[        R                  5      UR	                  S5      US	.U Vs0 s H  owR                  U_M     snD6$ s  snf )a  Constructs an instance of ResourceSpec from yaml data.

Args:
  yaml_data: dict, the parsed data from a resources.yaml file under
    command_lib/.
  is_positional: bool, optional value that determines if anchor argument is
    a positional and reformats anchor attribute name accordingly.
  api_version: string, overrides the default version in the resource
    registry if provided.

Returns:
  A ResourceSpec object.
r   )registry
collectionapi_versionr=   rA   disable_auto_completersplural_name)resource_collectionresource_namer   r   r   is_positionalr   )$googlecloudsdk.command_lib.util.apisr   GetAPICollectionParseAttributesFromDatagetdetailed_params	full_namer   r   disable_auto_completeparameter_name)cls	yaml_datar   r   r   r   r=   rE   s           r   FromYamlResourceSpec.FromYaml   s      >**,[ + :J(l#Z%?%?AJ M&00'** )%|'I'I!KMM-0#M AK
K
9##Y.

KM M Ls   B-resourcec                    X l         XPl        Xl        [        R                  R                  5       U l        U R                  R                  XS9U l        X@l	        U R                  R                  S5      n/ U l        0 U l        [        UR                  5       5      n	Sn
[        U5       H  u  pU[!        U5      S-
  :X  a  Sn
UR#                  U[%        5       5      nU R'                  XU
US9n[)        UUUR*                  SUR,                  UR.                  UR0                  UR2                  UR4                  S9	nU R                  R7                  U5        XR                  UR8                  '   M     U R                  (       d$  [;        SR=                  U R                   5      5      eU(       aD  [;        S	R=                  U R                   S
R?                  U5      S
R?                  U	5      5      5      eg)a!  Initializes a ResourceSpec.

To use a ResourceSpec, give a collection path such as
'cloudiot.projects.locations.registries', and optionally an
API version.

For each parameter in the collection path, an attribute is added to the
resource spec. Names can be created by default or overridden in the
attribute_configs dict, which maps from the parameter name to a
ResourceParameterAttributeConfig object. ResourceParameterAttributeConfigs
also contain information about the help text that describes the attribute.

Attribute naming: By default, attributes are named after their collection
path param names, or "name" if they are the "anchor" attribute (the final
parameter in the path).

Args:
  resource_collection: The collection path of the resource.
  resource_name: The name of the resource, which will be used in attribute
    help text. Defaults to 'resource'.
  api_version: Overrides the default version in the resource
    registry.
  disable_auto_completers: bool, whether to add completers automatically
    where possible.
  plural_name: str, the pluralized name. Will be pluralized by default rules
    if not given in cases where the resource is referred to in the plural.
  is_positional: bool, optional value that determines if anchor argument is
    a positional and reformats anchor attribute name accordingly.
  **kwargs: Parameter names (such as 'projectsId') from the
    collection path, mapped to ResourceParameterAttributeConfigs.

Raises:
  ResourceConfigurationError: if the resource is given unknown params or the
    collection has no params.
r    F   T)anchorr   )	rA   rt   ru   rv   rw   rx   rz   r   r   z?Resource [{}] has no parameters; no arguments will be generatedz_Resource [{}] was given an attribute config for unknown attribute(s): Expected [{}], Found [{}]r*   N) _namer   r   r   REGISTRYClone
_resourcesGetCollectionInfo_collection_infor   	GetParams_attributes_param_names_maplistkeys	enumeratelenpop ResourceParameterAttributeConfig_AttributeNamer   ru   rw   rx   rz   r   r   appendrA   r"   r.   r/   )r0   r   r   r   r   r   r   r   collection_paramsorig_kwargsr   irt   attribute_configattribute_namenew_attributes                   r   r-   ResourceSpec.__init__   s   L J")O((..0DO OO== > 6D#: --77;DDv{{}%KF"#45	
c#$q(	(J$D$FH**:289F + Hn  $..'44$..%00$4$N$N.BB	Dm m, 3=M..// 60 & (EEKV+/::F78 8 & (C )/tzz/3yy9J/K/3yy/E)GH H r   c                     U R                   $ rc   )r   r<   s    r   r=   ResourceSpec.attributesV  s    r   c                     U R                   $ rc   )r   r<   s    r   rA   ResourceSpec.nameZ  s    ::r   c                      U R                   S   $ )z'The "anchor" attribute of the resource.)r=   r<   s    r   r   ResourceSpec.anchor^  s     ??2r   c                     XR                   :H  $ zConvenience method.)r   rD   s     r   rF   ResourceSpec.IsAnchord  s    ##r   c                 $    U R                  U5      $ r   )rF   rD   s     r   rI   ResourceSpec.IsLeafAnchorh  s    ==##r   c                     U R                   $ )z.A map from all attribute names to param names.)r   r<   s    r   attribute_to_params_map$ResourceSpec.attribute_to_params_mapl  s        r   c                     U R                   $ rc   )r   r<   s    r   collection_infoResourceSpec.collection_infoq  s       r   c                     XR                   ;  aK  [        SR                  USR                  [	        U R                   R                  5       5      5      5      5      eU R                   U   $ )z<Gets the param name from attribute. Used for autocompleters.zDNo param name found for attribute [{}]. Existing attributes are [{}]r*   )r   rs   r.   r/   sortedr   )r0   r   s     r   	ParamNameResourceSpec.ParamNamex  sb    999		&)E)E)J)J)L"MNPQ Q ''77r   c                 \    U R                   R                  5        H  u  p#X1:X  d  M  Us  $    g)zAGets the attribute name from param name. Used for autocompleters.N)r   items)r0   rt   r   ps       r   AttributeNameResourceSpec.AttributeName  s/    !99??A	
 B r   c           	        ^^ 0 nUU4S jnU R                    H!  nU" UR                  5      X5R                  '   M#     U R                  R	                  U R
                  R                  U R
                  R                  5         U R                  R                  [        R                  " U R                  R                  TTS9U R                  UU R
                  R                  S9$ ! [        R                   a3  n[        SR                  U R                  [!        U5      5      5      eSnAf["        R$                   a  n[        [!        U5      5      eSnAff = f)a  Initializes a resource given its fallthroughs.

The fallthrough map is used to derive each resource attribute (including
the anchor). Returns a fully parsed resource object.

Args:
  fallthroughs_map: {str: [deps_lib._FallthroughBase]}, a dict of finalized
    fallthroughs for the resource.
  parsed_args: the argparse namespace.

Returns:
  (googlecloudsdk.core.resources.Resource) the fully initialized resource.

Raises:
  googlecloudsdk.calliope.concepts.concepts.InitializationError, if the
    concept can't be initialized.
c                    >^  UU U4S j$ )Nc                  4   > [         R                  " TT T5      $ rc   )deps_libGet)rL   rA   rM   s   r   <lambda>:ResourceSpec.Initialize.<locals>.LazyGet.<locals>.<lambda>  s    X\\$(8+Fr   r   )rA   rL   rM   s   `r   LazyGet(ResourceSpec.Initialize.<locals>.LazyGet  s	    FFr   rM   )r   paramsr   z/The [{}] resource is not properly specified.
{}N)r=   rA   rt   r   RegisterApiByNamer   api_namer   rV   r   r   r   r   AttributeNotFoundErrorr   r.   ry   r   	UserError)r0   rL   rM   r   r   rE   r3   s    ``    r   rN   ResourceSpec.Initialize  s   $ F
G __	%,Y^^%<f!!" %OO%%d&;&;&D&D&*&;&;&G&GI(__""
,,kk 0kK__++77 # 9 9 ** *vdiiQ(* *  (A''(s%   A!C$ $E8.D&&E=EEc                 T    U(       a  U R                  XUUS9$ U R                  XUUS9$ )a  Lazy parsing function for resource.

Generates resource based off of the parsed_args (user provided
arguments) and specified fallthrough behavior.

Args:
  attribute_to_args_map: {str: str}, A map of attribute names to the names
    of their associated flags.
  base_fallthroughs_map: {str: [deps.Fallthrough]}, A map of attribute
    names to non-argument fallthroughs, including command-level
    fallthroughs.
  parsed_args: the parsed Namespace.
  plural: bool, True if multiple resources can be parsed, False otherwise.
  allow_empty: bool, True if resource parsing is allowed to return no
    resource, otherwise False.

Returns:
  the initialized resources.Resource or a list of resources.Resource if the
    resource argument is plural.
)rU   )_ParseFromPluralValue_ParseFromValuerQ   s         r   rV   ResourceSpec.Parse  sI    , ''
! ( # # !!
! " # #r   c           
      \   0 UEn[         R                  " X@R                  U5        [         R                  " X@R                  R
                  U5        [         R                  " X@R                  U R                  U R                  UR                  U R                  R
                  / 5      5        U$ )a  Generate fallthrough map that is used to resolve resource params.

Used as source of truth for how each attribute is resolved. It is also used
to generate help text for both plural and singular resources.
Fallthroughs are a list of objects that, when called, try different ways of
resolving a resource attribute (see googlecloudsdk.calliope.concepts.
deps_lib._Fallthrough). This method builds a map from the name of each
attribute to its list of fallthroughs.

For each attribute, adds default flag fallthroughs and fully specified
anchor fallthroughs.

Args:
  attribute_to_args_map: {str: str}, A map of attribute names to the names
    of their associated flags.
  base_fallthroughs_map: {str: [deps.Fallthrough]}, A map of attribute
    names to non-argument fallthroughs, including command-level
    fallthroughs.
  parsed_args: Namespace | None, user's CLI input

Returns:
  {str: [deps.Fallthrough]}, a map from attribute name to all its
  fallthroughs.
)	r   AddFlagFallthroughsr=   UpdateWithValueFallthroughr   rA   AddAnchorFallthroughsr   r   )r0   rR   rS   rM   rL   s        r   rY   %ResourceSpec.BuildFullFallthroughsMap  s    4 1/0%%//+@B,,++**K9''//4;;8L8LT[[--r24 r   c                    0 UEn[         R                  " X@R                  U5        [         R                  " X@R                  R
                  5        [         R                  " X@R                  R
                  U5      nU H^  n[         R                  " X`R                  U R                  U R                  UR                  U R                  R
                  / 5      5        M`     U$ )a  Builds fallthrough map for each anchor value specified in a list.

For each anchor value, create a falthrough map to derive the rest
of the resource params. For each attribute, adds flag fallthroughs
and fully specified anchor fallthroughs. For each attribute,
adds default flag fallthroughs and fully specified anchor fallthroughs.

Args:
  attribute_to_args_map: {str: str}, A map of attribute names to the names
    of their associated flags.
  base_fallthroughs_map: FallthroughsMap, A map of attribute names to
    non-argument fallthroughs, including command-level fallthroughs.
  parsed_args: Namespace, used to parse the anchor value and derive
    fully specified fallthroughs.

Returns:
  list[FallthroughsMap], fallthrough map for each anchor value
)
r   r   r=   PluralizeFallthroughsr   rA   CreateValueFallthroughMapListr   r   r   )r0   rR   rS   rM   rL   map_listfull_maps          r   _BuildFullFallthroughsMapList*ResourceSpec._BuildFullFallthroughsMapList  s    ( 1/0%%//+@B''(8++:J:JK::++**K9H))
OOT[[$2F2F
,,t{{''
,. 
 Or   c                 v    U R                  XU5      n U R                  XSS9$ ! [         a    U(       a   ge f = f)z7Helper for parsing a singular resource from user input.r   N)rY   rN   r   )r0   rR   rS   rM   rU   rL   s         r   r   ResourceSpec._ParseFromValue  sQ     44kC__
  5 5 	s   # 88c                     U R                  XUS9n/ nU H#  nU R                  XsS9nUR                  U5        M%     U(       a  U$ U(       a  / $ U R                  X#S9$ )z7Helper for parsing a list of resources from user input.r   )r  rN   r   )	r0   rR   rS   rM   rU   r   parsed_resourcesrL   r   s	            r   r   "ResourceSpec._ParseFromPluralValue(  sv     11 2 !H $!1Khh' % 	i__2_LLr   c                     UR                   nU(       a?  Uc  U$ U(       a  U(       a  [        R                  " U5      $ [        R                  " U5      $ U(       a  gUR	                  SS5      R                  5       $ )aq  Chooses attribute name for a param name.

If attribute_config gives an attribute name, that is used. Otherwise, if the
param is an anchor attribute, 'name' is used, or if not, param_name is used.

Args:
  param_name: str, the parameter name from the collection.
  attribute_config: ResourceParameterAttributeConfig, the config for the
    param_name.
  anchor: bool, whether the parameter is the "anchor" or the last in the
    collection path.
  is_positional: bool, optional value that determines if anchor argument is
    a positional and reformats anchor attribute name accordingly.

Returns:
  (str) the attribute name.
rA   Id_id)r   format_util	SnakeCase	KebabCasereplacelower)r0   rt   r   r   r   r   s         r   r   ResourceSpec._AttributeName;  sl    & &44N 
	7Dk##N3 :((8:dE*0022r   c                    > [         [        U ]  U5      =(       a9    U R                  UR                  :H  =(       a    U R                  UR                  :H  $ rc   )r,   r   r`   r   r   r   s     r   r`   ResourceSpec.__eq__]  sL    ,,U3 N,,0M0MMN,,0M0MMOr   c                    > [         [        U ]  5       [        [	        [
        U R                  U R                  /5      5      -   $ rc   )r,   r   re   r   r   rd   r   r   r   s    r   re   ResourceSpec.__hash__b  s?    t-/#D4//1M1MNO3Q Q Qr   )r   r   r   r   r   r   r   r   r   rc   rg   )F)FN)r   r   r   r   r   r   classmethodr   r-   rh   r=   rA   r   rF   rI   r   r   r   r   rN   rV   rY   r  r   r   r   r`   re   r   r6   r7   s   @r   r   r      s   M M> 9C9NtVHp      
$$ ! ! ! !8*(Z 9>#@ GK"J GK H  %   %M& AF#' 3DO
Q Qr   r   c                   B    \ rS rSrSr\S 5       r        SS jrSrg)r   ig  zAConfiguration used to create attributes from resource parameters.c           
         US   nUS   nUS   n[         R                  R                  US5      nUR                  SS5      nUR                  S/ 5      nU Vs0 s H$  nUR                  S5      UR                  S	5      _M&     n	n[        R                  U5      =n
(       a  U
R
                  R                  5       nO/ n[        R                  " UR                  S
S5      5      nU=(       a    [        R                  " U5      nU(       a  X;  a  UR                  U5        UR                  S/ 5      n/ nU H  nS	U;   a6  UR                  [        R                  " US	   SU;   a  US   OS5      5        M?  SU;   d  MG  UR                  [        R                  " [         R                  R                  US   5      US   S95        M     X-  nU " UUUUUU	US9$ s  snf )zConstructs an attribute config from data defined in the yaml file.

Args:
  data: {}, the dict of data from the YAML file for this single attribute.

Returns:
  ResourceParameterAttributeConfig
r   r   helprx   r   Nr   	fieldNamevaluerh   r   rw   hinthook)r  )rA   ru   rw   rx   r   r   r   )r   HookFromDatar   "DEFAULT_RESOURCE_ATTRIBUTE_CONFIGSrw   copyr   
FromStringr   PropertyFallthroughr   ValueFallthroughFallthroughFromPath)r   datar   r   ru   rx   r   completion_request_params_listparamr   default_configrw   propprop_fallthroughfallthrough_datafallthroughs_from_hookfs                    r   r  )ResourceParameterAttributeConfig.FromDataj  s    *+N*+NVI		""45I((#8$?%)XX.I2%N" 4!3E 			+		' 223  !
 <??OO~O#00557ll   *b!9:DB < <T B,@*+ xx3	A%%%%'
1AfI$	

 Q;%%  !3!3AfI!>QvYO	
  *L!/";%' 'A!s   +GNc	                     Xl         X l        U=(       d    / U l        U(       a  U(       d  U(       a  [        S5      eX@l        XPl        X`l        U=(       d    [        U l        Xl	        g)a  Create a resource attribute.

Args:
  name: str, the name of the attribute. This controls the naming of flags
    based on the attribute.
  help_text: str, generic help text for any flag based on the attribute. One
    special expansion is available to convert "{resource}" to the name of
    the resource.
  fallthroughs: [deps_lib.Fallthrough], A list of fallthroughs to use to
    resolve the attribute if it is not provided on the command line.
  completer: core.cache.completion_cache.Completer, the completer
    associated with the attribute.
  completion_request_params: {str: value}, a dict of field names to static
    values to fill in for the completion request.
  completion_id_field: str, the ID field of the return value in the
    response for completion commands.
  value_type: the type to be accepted by the attribute arg. Defaults to str.
  parameter_name: the API parameter name that this attribute maps to.
zLCustom completer and auto-completer should not be specified at the same timeN)
r   ru   rw   rs   rx   r   r   ry   rz   r   )	r0   rA   ru   rw   rx   r   r   rz   r   s	            r   r-   )ResourceParameterAttributeConfig.__init__  sZ    8 N$*D/3F 4 5 5N%>"2 'CDO(r   )r   rx   r   r   rw   ru   r   rz   )NNNNNNNN)	r   r   r   r   r   r  r  r-   r   r   r   r   r   r   g  s7    I6' 6'r  )-#'"&)r   r   c                    U  Vs/ s H  n[         R                  U5      PM     nnU Vs/ s H  o"R                  PM     nn/ nU H  nU(       a4  XcS   R                  :X  a"  UR                  UR	                  S5      5        M>  U[
        ;   a7  [
        U   n[        R                  U5      nXhl        UR                  U5        M  [        UU5      e   U(       a  [        UU5      eU$ s  snf s  snf )a  Parses a list of ResourceParameterAttributeConfig from yaml data.

Args:
  attributes_data: dict, the attributes data defined in
    command_lib/resources.yaml file.
  expected_param_names: [str], the names of the API parameters that the API
    method accepts. Example, ['projectsId', 'instancesId'].

Returns:
  [ResourceParameterAttributeConfig].

Raises:
  InvalidResourceArgumentLists: if the attributes defined in the yaml file
    don't match the expected fields in the API method.
r   )	r   r  r   r   r   r+   r  r   r%   )	attributes_dataexpected_param_namesaraw_attributesregistered_param_namesfinal_attributesexpected_namer   ignored_attributes	            r   r   r     s   " =L<Kq&//2O   7EEn,,nE ,m-!+<+K+KKn0034	.	( &m4n<@@P)6&/0 ))=)?A A! ,&  '';'=? ? 
A Fs
   C'C,z:Project ID of the Google Cloud project for the {resource}.z	--project)rA   ru   rw   )(r   
__future__r   r   r   ri   rq    googlecloudsdk.calliope.conceptsr   r   r   r   r  r   r	   googlecloudsdk.corer
   r   r   r+   r   r   r"   r%   objectABCMetar9   rm   r   r   r   r   ArgFallthroughr"  VALUEScorer    DEFAULT_PROJECT_ATTRIBUTE_CONFIGr  _DEFAULT_CONFIGSr   r   r   <module>rE     s2   * '  ' 
 	 = : @ Q * * ) .J ..% .5 555 5+3&CKK +3\4O 4On/
 /DKQ; KQ\b)v b)J0f $D	J 	,$$Z%6%6%;%;%C%CD	$   /&1 "?@ r   