
                            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ZddlZddlm	Z	 ddl
mZ dd	lmZ  ej                  d
d      Z eddddd       eddddd       eddddd       eddddd       eddddd       eddddd        ed!d"d!dd#       ed$d%d&d'd(       ed)d*d)dd+       ed,d-d.dd/       ed0d1d2dd3      gZeD  ci c]  } | j"                  |  c} Zd4 Zd5 Zd;d7Z e       dd6fd8Z e       d9ddd6d6dfd:Zyc c} w )<z@Specifications for resource-identifying command line parameters.    )absolute_import)division)print_function)unicode_literalsN)arg_parsers)concepts)concept_parsersEntityNamesz=singular plural docs_name valid_pattern secondary_descriptionprojectprojectsz&GCP project containing the {resource}.organizationorganizationsz^[a-z][-a-z0-9]{0,30}[a-z0-9]$zApigee organization containing the {resource}. If unspecified, the Cloud Platform project's associated organization will be used.apiapisz	API proxyz^[\s\w.-]{1,255}$zAPI proxy for the {resource}.environmentenvironmentsz)Deployment environment of the {resource}.revision	revisionszRevision of the {resource}.
deploymentdeploymentsz&Relevant deployment of the {resource}.	operation
operationsz&Operation operating on the {resource}.productapiproductszAPI productz^[A-Za-z0-9._$ %-]+$z$Relevant product for the {resource}.	developer
developerszDeveloper of the {resource}.appappsapplicationz(Relevant application for the {resource}.archive_deploymentarchiveDeploymentszarchive deploymentz!Archive deployment for {resource}c                 4    t         |    j                  }|dS |S )Nz.*)ENTITIESvalid_pattern)namepatterns     6lib/googlecloudsdk/command_lib/apigee/resource_args.py_ValidPatternForEntityr(   G   s     TN(('/.w.    c                 >    t        j                  t        |             S )zEReturns a compiled regex that matches valid values for `entity_name`.)recompiler(   )entity_names    r'   ValidPatternForEntityr.   L   s    	*;7	88r)   Fc                     d}|r3t        j                  t        |        dj                  t        |           }t        j                  | t        |    j                  ||xs t        |    j                  |      S )a  Returns a ResourceParameterAttributeConfig for the attribute named `name`.

  Args:
    name: singular name of the attribute. Must exist in ENTITIES.
    fallthroughs: optional list of gcloud fallthrough objects which should be
      used to get this attribute's value if the user doesn't specify one.
    help_text: help text to use for this resource parameter instead of the
      default help text for the attribute.
    validate: whether to check that user-provided value for this attribute
      matches the expected pattern.
  Nz*Must match the format of a valid {2} ({3}))r%   parameter_name
value_type	help_textfallthroughs)	r   RegexpValidatorr(   formatr#   r    ResourceParameterAttributeConfigpluralsecondary_description)r%   r3   r2   validate	validators        r'   AttributeConfigr;   Q   sw     )++t$;4;;Xd^LNI 
	2	2d^**AXd^AA
! !r)   c                    t        j                  d |xs i       }| D cg c]  }t        |    }}i }|D ]W  }|D cg c]  }|j                  |v r| }	}t	        |j                  |	||j                     |      }
|
||j
                  dz   <   Y t        j                  ddj                  d |D              z   fd|d   j                  i|S c c}w c c}w )	a  Returns a ResourceSpec for the resource path `path`.

  Args:
    path: a list of attribute names. All must exist in ENTITIES.
    fallthroughs: optional list of googlecloudsdk.command_lib.apigee.Fallthrough
      objects which will provide default values for the attributes in `path`.
    help_texts: a mapping of attribute names to help text strings, to use
      instead of their default help text.
    validate: whether to check that the user-provided resource matches the
      expected naming conventions of the resource path.
  c                       y N r?   r)   r'   <lambda>zResourceSpec.<locals>.<lambda>w   s    tr)   r9   Idzapigee..c              3   4   K   | ]  }|j                     y wr>   )r7   ).0entitys     r'   	<genexpr>zResourceSpec.<locals>.<genexpr>   s     @xV6==xs   resource_name)
collectionsdefaultdictr#   singularr;   r7   r   ResourceSpecjoin	docs_name)pathr3   
help_textsr9   r%   entitiesidsrF   fallthroughrelevant_fallthroughsconfigs              r'   rM   rM   k   s     &&|Z5E2F*)-.htn(.
#f'3'3??k) 	|   6??#	F
 !'C  
		#((@x@@@
RL**
 	
  /s
   CCTc
           	         |j                  d      }
|-|
d   }|r|j                         }nd|j                  dd      z   }||}t        j                  j                  |t        |
||	|      |||      j                  |        y)	a=  Creates a concept parser for `resource_path` and adds it to `parser`.

  Args:
    parser: the argparse.ArgumentParser to which the concept parser will be
      added.
    resource_path: path to the resource, in `entity.other_entity.leaf` format.
    help_text: the help text to display when describing the resource as a whole.
    fallthroughs: fallthrough providers for entities in resource_path.
    positional: whether the leaf entity should be provided as a positional
      argument, rather than as a flag.
    argument_name: what to name the leaf entity argument. Defaults to the leaf
      entity name from the resource path.
    required: whether the user is required to provide this resource. Defaults to
      True for positional arguments, False otherwise.
    prefixes: whether to append prefixes to the non-leaf arguments.
    validate: whether to check that the user-provided resource matches the
      expected naming conventions of the resource path.
    help_texts: custom help text for generated arguments. Defaults to each
      entity using a generic help text.
  rC   NrI   z--_-rA   )requiredprefixes)splitupperreplacer	   ConceptParserForResourcerM   AddToParser)parserresource_pathr2   r3   
positionalargument_namerZ   r[   r9   rQ   
split_pathleaf_element_names               r'   AddSingleResourceArgumentrh      s    < ""3'*"2'--/m.66sC@@mH++:|Z(K , 
 %V,r)   )NNF)__doc__
__future__r   r   r   r   rJ   r+   googlecloudsdk.callioper    googlecloudsdk.calliope.conceptsr   (googlecloudsdk.command_lib.util.conceptsr	   
namedtuple_EntityNames_ENTITY_TUPLESrL   r#   r(   r.   r;   tuplerM   rh   )items   0r'   <module>rs      s   G &  % '  	 / 5 D &{%%CE
 J
D9;)	%& -A022<> [*d.0}lD9;lK9;M=(79 lK/1t;=%';%t467> -;;NDDMM4N;/
9
!4 %*Gu H ,17)-,0'+',',)-.-Q <s   D