
    71                         S 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\	5      r
 " S	 S
\
5      r " S S\5      r " S S\
5      rg)zClasses to define how concept args are added to argparse.

A PresentationSpec is used to define how a concept spec is presented in an
individual command, such as its help text. ResourcePresentationSpecs are
used for resource specs.
    )absolute_import)division)unicode_literals)util)info_holdersc                   Z    \ rS rSrSr      S
S jr\S 5       r\S 5       rS r	S r
S	rg)PresentationSpec   a  Class that defines how concept arguments are presented in a command.

Attributes:
  name: str, the name of the main arg for the concept. Can be positional or
    flag style (UPPER_SNAKE_CASE or --lower-train-case).
  concept_spec: googlecloudsdk.calliope.concepts.ConceptSpec, The spec that
    specifies the concept.
  group_help: str, the help text for the entire arg group.
  prefixes: bool, whether to use prefixes before the attribute flags, such as
    `--myresource-project`.
  required: bool, whether the anchor argument should be required. If True, the
    command will fail at argparse time if the anchor argument isn't given.
  plural: bool, True if the resource will be parsed as a list, False
    otherwise.
  group: the parser or subparser for a Calliope command that the resource
    arguments should be added to. If not provided, will be added to the main
    parser.
  attribute_to_args_map: {str: str}, dict of attribute names to names of
    associated arguments.
  hidden: bool, True if the arguments should be hidden.
Nc
                     Xl         X l        X0l        X@l        XPl        Xpl        Xl        U R                  U5      U l        Xl	        g)a  Initializes a ResourcePresentationSpec.

Args:
  name: str, the name of the main arg for the concept.
  concept_spec: googlecloudsdk.calliope.concepts.ConceptSpec, The spec that
    specifies the concept.
  group_help: str, the help text for the entire arg group.
  prefixes: bool, whether to use prefixes before the attribute flags, such
    as `--myresource-project`. This will match the "name" (in flag format).
  required: bool, whether the anchor argument should be required.
  flag_name_overrides: {str: str}, dict of attribute names to the desired
    flag name. To remove a flag altogether, use '' as its rename value.
  plural: bool, True if the resource will be parsed as a list, False
    otherwise.
  group: the parser or subparser for a Calliope command that the resource
    arguments should be added to. If not provided, will be added to the main
    parser.
  hidden: bool, True if the arguments should be hidden.
N)
name_concept_spec
group_helpprefixesrequiredpluralgroup_GetAttributeToArgsMap_attribute_to_args_maphidden)
selfr   concept_specr   r   r   flag_name_overridesr   r   r   s
             Blib/googlecloudsdk/command_lib/util/concepts/presentation_specs.py__init__PresentationSpec.__init__5   sC    : I% OMMKJ"&"="=#DK    c                     U R                   $ )zThe ConceptSpec associated with the PresentationSpec.

Returns:
  (googlecloudsdk.calliope.concepts.ConceptSpec) the concept spec.
)r   r   s    r   r   PresentationSpec.concept_spec]   s     r   c                     U R                   $ )zPThe map of attribute names to associated args.

Returns:
  {str: str}, the map.
)r   r   s    r   attribute_to_args_map&PresentationSpec.attribute_to_args_mapf   s     &&&r   c                     [         e)a2  Generate a ConceptInfo object for the ConceptParser.

Must be overridden in subclasses.

Args:
  fallthroughs_map: {str: [googlecloudsdk.calliope.concepts.deps.
    _FallthroughBase]}, dict keyed by attribute name to lists of
    fallthroughs.

Returns:
  info_holders.ConceptInfo, the ConceptInfo object.
NotImplementedErrorr   fallthroughs_maps     r   _GenerateInfoPresentationSpec._GenerateInfoo   s
     r   c                     [         e)zGenerate a map of attributes to primary arg names.

Must be overridden in subclasses.

Args:
  flag_name_overrides: {str: str}, the dict of flags to overridden names.

Returns:
  {str: str}, dict from attribute names to arg names.
r$   )r   r   s     r   r   'PresentationSpec._GetAttributeToArgsMap~   s
     r   )	r   r   r   r   r   r   r   r   r   )FFNFNF)__name__
__module____qualname____firstlineno____doc__r   propertyr   r!   r(   r   __static_attributes__ r   r   r	   r	      sS    4 #'&P   ' 'r   r	   c                   H    \ rS rSrSrS rS r\  S
S j5       rS r	S r
S	rg)ResourcePresentationSpec   zGClass that specifies how resource arguments are presented in a command.c                 Z   U(       d  g UR                  5        H  nU R                  R                   H  nUR                  U:X  d  M    M1     [	        SR                  USR                  U R                  R                   Vs/ s H  nUR                  PM     sn5      5      5      e   g s  snf )NzmAttempting to override the name for an attribute not present in the concept: [{}]. Available attributes: [{}], )keysr   
attributesr   
ValueErrorformatjoin)r   r   attribute_name	attributes       r   _ValidateFlagNameOverrides3ResourcePresentationSpec._ValidateFlagNameOverrides   s    -224((33)>>^+
 4 <<BF		,0,=,=,H,HJ,Hy %>>,HJ K=LM 	M 5Js    B(c           	      T   U R                  U5        0 n[        U R                  R                  5       Hq  u  p4U[	        U R                  R                  5      S-
  :H  nU R                  UR                  U R                  XR                  US9nU(       d  Mc  XbUR                  '   Ms     U$ )N   )	is_anchor)r@   	enumerater   r:   lenGetFlagNamer   r   )r   r   r!   ir?   rD   r   s          r   r   /ResourcePresentationSpec._GetAttributeToArgsMap   s    ##$78!$"4"4"?"?@s4--889A==i
..$))%8--  d 
04inn- A ! r   Nc                 v   U=(       d    0 nX;   a  UR                  U 5      $ U S:X  a  gU(       a  U$ [        R                  nU(       an  UR                  [        R                  5      (       a%  XQ[	        [        R                  5      S S-   -  nXP-   $ XQR                  5       R                  SS5      S-   -  nXP-   $ )a  Gets the flag name for a given attribute name.

Returns a flag name for an attribute, adding prefixes as necessary or using
overrides if an override map is provided.

Args:
  attribute_name: str, the name of the attribute to base the flag name on.
  presentation_name: str, the anchor argument name of the resource the
    attribute belongs to (e.g. '--foo').
  flag_name_overrides: {str: str}, a dict of attribute names to exact string
    of the flag name to use for the attribute. None if no overrides.
  prefixes: bool, whether to use the resource name as a prefix for the flag.
  is_anchor: bool, True if this it he anchor flag, False otherwise.

Returns:
  (str) the name of the flag.
project N-_)getr   PREFIX
startswithrF   lowerreplace)r>   presentation_namer   r   rD   prefixs         r   rG   $ResourcePresentationSpec.GetFlagName   s    ( .3, $$^44"[[F		%	%dkk	2	2C$4$56<< "" 	))+33C=CC""r   c                     [         R                  " U R                  U R                  U R                  U R
                  UU R                  U R                  U R                  U R                  S9	$ )a  Gets the ResourceInfo object for the ConceptParser.

Args:
  fallthroughs_map: {str: [googlecloudsdk.calliope.concepts.deps.
    _FallthroughBase]}, dict keyed by attribute name to lists of
    fallthroughs.

Returns:
  info_holders.ResourceInfo, the ResourceInfo object.
)r   r   r   r   )
r   ResourceInfor   r   r   r!   r   r   r   r   r&   s     r   r(   &ResourcePresentationSpec._GenerateInfo   sV     $$		""{{jj{{	 	r   c                 *   [        U[        U 5      5      (       d  gU R                  UR                  :H  =(       a    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  $ NF

isinstancetyper   r   r   r   r   r   r   r   r   others     r   __eq__ResourcePresentationSpec.__eq__       eT$Z((II# (!3!33(OOu///( MMU^^+( 15u||0K( MMU^^+	( 15

ekk0I	(
 KK5<<')r   r3   NFF)r,   r-   r.   r/   r0   r@   r   staticmethodrG   r(   ra   r2   r3   r   r   r5   r5      s5    OM! IM,1 #  #D,)r   r5   c                       \ rS rSrSrSrg)InvalidPresentationSpecError   z$Error for invalid presentation spec.r3   N)r,   r-   r.   r/   r0   r2   r3   r   r   rg   rg      s    ,r   rg   c                   B    \ rS rSrSrS r\  S	S j5       rS rS r	Sr
g)
!MultitypeResourcePresentationSpec   z&A resource-specific presentation spec.c           
         0 nU R                   R                   Vs/ s H'  nU R                   R                  U5      (       d  M%  UPM)     nn[        U5      S:  az  [        R
                  " U R                  5      (       aU  SR                  S U 5       5      n[        SU SU R                   S[        R                  " U R                  5       S35      eU R                   R                   HQ  nU/U:H  nU R                  UR                  U R                  UU R                  US9nU(       d  MC  XUR                  '   MS     U$ s  snf )	NrC   r8   c              3   8   #    U  H  oR                   v   M     g 7f)N)r   ).0as     r   	<genexpr>KMultitypeResourcePresentationSpec._GetAttributeToArgsMap.<locals>.<genexpr>   s     <|!vv|s   z Multitype resource has anchors [z] and positional name [z]. Multitype resource can only be non-positional or have a single anchor. Update multitype collections or change the presentation name to .)r   r   rD   )r   r:   IsLeafAnchorrF   r   IsPositionalr   r=   rg   FlagNameFormatrG   r   )	r   r   r!   ro   leaf_anchorsanchor_namesr?   rD   r   s	            r   r   8MultitypeResourcePresentationSpec._GetAttributeToArgsMap   s4   #11<< ;<!))66q9 <L ; <1!2!2499!=!=YY<|<<l(,\N ;99+ &&*&9&9$))&D%EQHI I ''22	+-i
..$))9L==I  7d 
04inn- 3 ! %;s   $EENc                     U=(       d    0 nX;   a  UR                  U 5      $ U(       a  U$ U S:X  a  gU(       a&  [        R                  " SR                  X/5      5      $ [        R                  " U 5      $ )a  Gets the flag name for a given attribute name.

Returns a flag name for an attribute, adding prefixes as necessary or using
overrides if an override map is provided.

Args:
  attribute_name: str, the name of the attribute to base the flag name on.
  presentation_name: str, the anchor argument name of the resource the
    attribute belongs to (e.g. '--foo').
  flag_name_overrides: {str: str}, a dict of attribute names to exact string
    of the flag name to use for the attribute. None if no overrides.
  prefixes: bool, whether to use the resource name as a prefix for the flag.
  is_anchor: bool, True if this is the anchor flag, False otherwise.

Returns:
  (str) the name of the flag.
rK   rL   rM   )rO   r   ru   r=   )r>   rT   r   r   rD   s        r   rG   -MultitypeResourcePresentationSpec.GetFlagName  sl    ( .3, $$^44"  +<*M!NOO  00r   c                     [         R                  " U R                  U R                  U R                  U R
                  UU R                  U R                  U R                  S9$ )a"  Gets the MultitypeResourceInfo object for the ConceptParser.

Args:
  fallthroughs_map: {str: [googlecloudsdk.calliope.concepts.deps.
    _FallthroughBase]}, dict keyed by attribute name to lists of
    fallthroughs.

Returns:
  info_holders.MultitypeResourceInfo, the ResourceInfo object.
)r   r   r   )	r   MultitypeResourceInfor   r   r   r!   r   r   r   r&   s     r   r(   /MultitypeResourcePresentationSpec._GenerateInfo/  sO     --		""{{jj r   c                 *   [        U[        U 5      5      (       d  gU R                  UR                  :H  =(       a    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  $ r[   r\   r_   s     r   ra   (MultitypeResourcePresentationSpec.__eq__D  rc   r   r3   rd   )r,   r-   r.   r/   r0   r   re   rG   r(   ra   r2   r3   r   r   rj   rj      s/    .!. IM,11 1@*)r   rj   N)r0   
__future__r   r   r    googlecloudsdk.calliope.conceptsr   (googlecloudsdk.command_lib.util.conceptsr   objectr	   r5   	Exceptionrg   rj   r3   r   r   <module>r      sU    '  ' 1 Akv k\`)/ `)F-9 -
X)(8 X)r   