
    8#                     R    S r SSKrSSKJr  S rS rS rS rS r	S	 r
S
 rS rS rg)z7Utilities for generating and updating fallthrough maps.    N)depsc                 <   U H  nU R                  UR                  / 5      nUR                  UR                  5      =n(       a  [        R                  " U5      nOSnU(       a   U Vs/ s H  owU:w  d  M
  UPM     nnU/U-   n	OUn	XUR                  '   M     gs  snf )a  Adds flag fallthroughs to fallthrough map.

Iterates through each attribute and prepends a flag fallthrough.
This allows resource attributes to be resolved to flag first. For example:

  {'book': [deps.ValueFallthrough('foo')]}

will update to something like...

  {
      'book': [
          deps.ArgFallthrough('--foo'),
          deps.ValueFallthrough('foo')
      ]
  }

Args:
  base_fallthroughs_map: {str: [deps._FallthroughBase]}, A map of attribute
    names to fallthroughs
  attributes: list[concepts.Attribute], list of attributes associated
    with the resource
  attribute_to_args_map: {str: str}, A map of attribute names to the names
    of their associated flags.
N)getnamedeps_libArgFallthrough)
base_fallthroughs_map
attributesattribute_to_args_map	attributecurrent_fallthroughsarg_namearg_fallthroughffiltered_fallthroughsfallthroughss
             5lib/googlecloudsdk/calliope/concepts/deps_map_util.pyAddFlagFallthroughsr      s    4 i044Y^^RH(,,Y^^<<x< //9oo)C)/-A!)  C%&)>>l)l,8)..) Cs   (	B5Bc                    U Hu  nU R                  UR                  / 5      n[        R                  " XCUR                  5      nXR:w  a   U Vs/ s H  oU:w  d  M
  UPM     n	nU/U	-   n
OUn
XUR                  '   Mw     gs  snf )a  Adds fully specified fallthroughs to fallthrough map.

Iterates through each attribute and prepends a fully specified fallthrough.
This allows resource attributes to resolve to the fully specified anchor
value first. For example:

  {'book': [deps.ValueFallthrough('foo')]}

will udpate to something like...

  {
      'book': [
          deps.FullySpecifiedAnchorFallthrough(anchor_fallthroughs),
          deps.ValueFallthrough('foo')
      ]
  }

Args:
  base_fallthroughs_map: {str: [deps._FallthroughBase]}, A map of attribute
    names to fallthroughs
  attributes: list[concepts.Attribute], list of attributes associated
    with the resource
  anchor: concepts.Attribute, attribute that the other attributes should
    resolve to if fully specified
  collection_info: the info of the collection to parse the anchor as
  anchor_fallthroughs: list[deps._FallthroughBase], fallthroughs used to
    resolve the anchor value
N)r   r   r   FullySpecifiedAnchorFallthrough
param_name)r	   r
   anchorcollection_infoanchor_fallthroughsr   r   anchor_based_fallthroughr   r   r   s              r   AddAnchorFallthroughsr   A   s    > i044Y^^RH'GGi.B.B D )L)2J-J!)  L./2GGl)l,8)..) Ls   	A=A=c                 Z    U(       d  g[        XU5      u  p4U(       a  [        XUU5        gg)a0  Shortens fallthrough list to a single deps.ValueFallthrough.

Used to replace the attribute_name entry in a fallthrough map to a
single ValueFallthrough. For example:

  {'book': [deps.Fallthrough(lambda: 'foo')]}

will update to something like...

  {'book': [deps.ValueFallthrough('foo')]}

Args:
  base_fallthroughs_map: {str: [deps._FallthroughBase]}, A map of attribute
    names to fallthroughs we are updating
  attribute_name: str, entry in fallthrough map we are updating
  parsed_args: Namespace | None, used to derive the value for ValueFallthrough
N)_GetFallthroughAndValue_UpdateMapWithValueFallthrough)r	   attribute_nameparsed_argsattribute_valueattribute_fallthroughs        r   UpdateWithValueFallthroughr$   n   s6    & 

+B[,:(/ "     c                     [        XU5      u  p4/ nU(       d  U$ U H$  n0 U En[        XvX5        UR                  U5        M&     U$ )a   Generates a list of fallthrough maps for each anchor value in a list.

For each anchor value, generate a fallthrough map. For example, if user
provides anchor values ['foo', 'bar'] and a base fallthrough like...

  {'book': [deps.ArgFallthrough('--book')]}

will generate something like...

  [
      {'book': [deps.ValueFallthrough('foo')]},
      {'book': [deps.ValueFallthrough('bar')]}
  ]

Args:
  base_fallthroughs_map: {str: [deps._FallthroughBase]}, A map of attribute
    names to fallthroughs we are updating
  attribute_name: str, entry in fallthrough map we are updating
  parsed_args: Namespace | None, used to derive the value for ValueFallthrough

Returns:
  list[{str: deps._FallthroughBase}], a list of fallthrough maps for
  each parsed anchor value
)r   r   append)r	   r    r!   attribute_valuesr#   map_listvaluenew_maps           r   CreateValueFallthroughMapListr,      s\    4 -D[-:) (	Oe'&'G"?OOG	  
 
/r%   c                 n    U R                  U/ 5      nU Vs/ s H  n[        U5      PM     snX'   gs  snf )a  Updates fallthrough map entry to make fallthroughs plural.

For example:

  {'book': [deps.ArgFallthrough('--foo')]}

will update to something like...

  {'book': [deps.ArgFallthrough('--foo'), plural=True]}

Args:
  base_fallthroughs_map: {str: [deps.Fallthrough]}, A map of attribute
    names to fallthroughs we are updating
  attribute_name: str, entry in fallthrough map we are updating
N)r   _PluralizeFallthrough)r	   r    given_fallthroughsfallthroughs       r   PluralizeFallthroughsr1      sD      -00D ,+++ K(++' +s   2c                 @    [         R                  " U 5      nSUl        U$ )NT)copydeepcopyplural)r0   plural_fallthroughs     r   r.   r.      s     }}[1"	r%   c                 b    [         R                  " UUR                  UR                  S9nU/X'   g )N)active)r   ValueFallthroughhintr8   )r	   r*   r    r#   value_fallthroughs        r   r   r      s6    //  "))+ ,=*='r%   c                     UR                  U / 5       H  n UR                  U5      nXC4s  $    g! [        R                   a     M4  f = f)z=Derives value and fallthrough used to derives value from map.)NN)r   GetValuer   FallthroughNotFoundError)r    fallthroughs_mapr!   possible_fallthroughr*   s        r   r   r      sX    .22>2F"++K8e** G  ,, s   0AAc                 2   U R                  5        H  u  pSnU Hv  nU(       aW  UR                  (       aF  UR                  R                  nUR                  R                  nSU SU SU SU SU S3nSU4s  s  $ UR                  (       a  Mt  UnMx       g	   g)
a  Validates fallthrough map to ensure fallthrough map is not invalid.

Fallthrough maps are only invalid if an inactive fallthrough comes before
an active fallthrough. It could result in an active fallthrough that can
never be reached.

Args:
  fallthroughs_map: {str: [deps._FallthroughBase]}, A map of attribute
    names to fallthroughs we are validating

Returns:
  (bool, str), bool for whether fallthrough map is valid and str for
    the error message
Nz-Invalid Fallthrough Map: Fallthrough map at [z!] contains inactive fallthrough [z] before active fallthrough [z-]. Fix the order so that active fallthrough [z-] is reachable or remove active fallthrough [z].F)TN)itemsr8   	__class____name__)r?   attrr   inactive_fallthroughr0   
active_strinactive_strmsgs           r   ValidateFallthroughMaprJ      s      -224d#	+"4"4 **33
+55>>>tf E((4~ 6)l +)l +)l"	.
 cz* $ ! 5r%   )__doc__r3    googlecloudsdk.calliope.conceptsr   r   r   r   r$   r,   r1   r.   r   r   rJ    r%   r   <module>rN      s@    >  =(9V*9Z>&R0>	 r%   