
                         \   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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rSrSrSrSrSrSrSrSrSrSrSrSrSrSr Sr!Sr"Sr#Sr$Sr%Sr&Sr'S r(S!r)S"r*S#r+S$r,S%r-S&r.S'r/S(r0S)r1S*r2S+r3S,r4S-r5S.r6S/r7S0r8S1r9S2r:S3r;S4r< " S5 S6\Rz                  5      r= " S7 S8\=5      r> " S9 S:\=5      r? " S; S<\=5      r@ " S= S>\=5      rA " S? S@\=5      rB " SA SB\=5      rCSC rDSD rESE rFSF rG " SG SH\H5      rI " SI SJ\I5      rJ " SK SL\J5      rK " SM SN\J5      rL " SO SP\I5      rM " SQ SR\M5      rN " SS ST\H5      rO " SU SV\R                  5      rQSWrRSX rSSY rTSZ rUS[ rV\S4S\ jrW\S4S] jrXS\S4S^ jrYS\S4S_ jrZS` r[SeSa jr\Sb r] SfSc jr^       SgSd jr_g)hz<A module for the Cloud SDK CLI tree external representation.    )absolute_import)division)unicode_literalsN)walker)config)
exceptions)module_util)files1gcloudREADONLYUNKNOWNHEADTEST	argumentsCLI_VERSIONVERSIONattrcapsulecategorychoiceshidden_choicescommands	completerconstraintsdefaultdescriptionflagsgroupgroupsinverted_synopsis	is_globalis_group	is_hiddenis_mutexis_positionalis_requirednamealternative_namesnargspathpositionalspropertyreleaserequiredsectionstypeuniverse_compatibledefault_universe_compatiblevaluec                       \ rS rSrSrSrg)Errore   zBase exception for this module. N__name__
__module____qualname____firstlineno____doc____static_attributes__r8       'lib/googlecloudsdk/calliope/cli_tree.pyr6   r6   e   s    'r@   r6   c                       \ rS rSrSrSrg)CliCommandVersionErrori   z-Loaded CLI tree CLI command version mismatch.r8   Nr9   r8   r@   rA   rC   rC   i   s    5r@   rC   c                       \ rS rSrSrSrg)SdkRootNotFoundErrorm   z Raised if SDK root is not found.r8   Nr9   r8   r@   rA   rF   rF   m   s    (r@   rF   c                       \ rS rSrSrSrg)SdkConfigNotFoundErrorq   z*Raised if SDK root config/ does not exist.r8   Nr9   r8   r@   rA   rI   rI   q   s    2r@   rI   c                       \ rS rSrSrSrg)SdkDataCliNotFoundErroru   z,Raised if SDK root data/cli/ does not exist.r8   Nr9   r8   r@   rA   rL   rL   u   s    4r@   rL   c                       \ rS rSrSrSrg)CliTreeVersionErrory   z!Loaded CLI tree version mismatch.r8   Nr9   r8   r@   rA   rO   rO   y   s    )r@   rO   c                       \ rS rSrSrSrg)CliTreeLoadError}   zCLI tree load error.r8   Nr9   r8   r@   rA   rR   rR   }   s    r@   rR   c                      g)z6Mock function that returns True if running under test.Fr8   r8   r@   rA   _IsRunningUnderTestrU      s    	r@   c                     [        5       (       a  [        $ [        R                  n U [        :w  a  U $  SSKJn  UR                  5       nUR                  5       nUS   n U $ ! [        [        R                  4 a     U $ f = f)z'Return the default CLI command version.r   )update_managercore)rU   TEST_CLI_VERSION_TESTr   CLOUD_SDK_VERSIONTEST_CLI_VERSION_HEADgooglecloudsdk.core.updaterrW   UpdateManagerGetCurrentVersionsInformationKeyErrorr   r6   )versionrW   manager
componentss       rA   _GetDefaultCliCommandVersionrc      s      $$'%%N		:**,G668J G 
. J$$	% 		.	s   +A   A>=A>c                 0    SSK Jn  UR                  U 5      $ )z/Returns the most detailed description from arg.r   )
usage_text)googlecloudsdk.calliopere   GetArgDetails)argre   s     rA   _GetDescriptionri      s    0		!	!#	&&r@   c                     [        U 5      (       a  U " 5       n U (       a  [        R                  " U 5      n [        R                  " U =(       d    S5      $ )zyNormalizes description text.

Args:
  description: str, The text to be normalized.

Returns:
  str, The normalized text.
 )callabletextwrapdedentsix	text_type)r   s    rA   _NormalizeDescriptionrq      s;     k-K//+.K	{(b	))r@   c                       \ rS rSrSrS rSrg)Argument   a  Group, Flag or Positional argument.

Attributes:
  attr: dict, Miscellaneous {name: value} attributes.
  description: str, The help text.
  is_hidden: bool, True if the argument help text is disabled.
  is_group: bool, True if this is an argument group.
  is_positional: bool, True if this is a positional argument.
  is_mutex: bool, True if this is a mutex group.
  is_required: bool, The argument must be specified.
c           	          0 U l         [        [        U5      5      U l        SU l        [        US[        USS5      5      U l        SU l        [        US[        USS5      5      U l        UR                  U l	        g )NFr$   hiddenr%   mutex)
r   rq   ri   r   r#   getattrr$   r&   r%   r'   )selfrh   s     rA   __init__Argument.__init__   sh    DI,_S-ABDDMS+wsHe/LMDNDCWS'5-IJDMDr@   )r   r   r#   r$   r%   r&   r'   Nr:   r;   r<   r=   r>   rz   r?   r8   r@   rA   rs   rs      s    
'r@   rs   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )FlagOrPositional   a  Group, Flag or Positional argument.

Attributes:
  category: str, The argument help category name.
  completer: str, Resource completer module path.
  default: (self.type), The default flag value or None if no default.
  description: str, The help text.
  name: str, The normalized name ('_' => '-').
  nargs: {0, 1, '?', '*', '+'}
  value: str, The argument value documentation name.
  alternative_names: list, The list of alternative names.
c                   > [         [        U ]  U5        [        U[        S5      U l        [        U[        S 5      nU(       a#   UR                  n[        R                  " U5      nX0l        UR                  U l        [        [        U5      5      U l        [         R"                  " U5      U l        [        U[&        / 5      U l        [         R"                  " UR*                  =(       d    S5      U l        UR,                  (       a&  [         R"                  " UR,                  5      U l        O>U R$                  R1                  S5      R3                  SS5      R5                  5       U l        U R7                  5         g ! [         a    Un GN:f = f)Nrk   r   -_)superr~   rz   rx   LOOKUP_CATEGORYr   LOOKUP_COMPLETERcompleter_classAttributeErrorr	   GetModulePathr   r   rq   ri   r   ro   rp   r(   LOOKUP_ALTERNATIVE_NAMESr)   r*   metavarr4   lstripreplaceupper_Scrub)ry   rh   r(   r   r   	__class__s        rA   rz   FlagOrPositional.__init__   s   	
D*3/C"5DM-t4I$#33 ++O<iN;;DL,_S-ABDd#DI$S*BBGDsyy~A.DJ
{{==-dj99##C(00c:@@BdjKKM  $#$s   E; ;F
Fc                 P   [        U R                  [        R                  5      (       d  g[        R
                  " SU R                  5      (       d  gSU l        [        R
                  " SU R                  [        R                  5      nU(       a  UR                  S5      U l        gg)a!  Scrubs private paths in the default value and description.

Argument default values and "The default is ..." description text are the
only places where dynamic private file paths can leak into the cli_tree.
This method is called on all args.

The test is rudimentary but effective. Any default value that looks like an
absolute path on unix or windows is scrubbed. The default value is set to
None and the trailing "The default ... is ..." sentence in the description,
if any, is deleted. It's OK to be conservative here and match aggressively.
Nz/|[A-Za-z]:\\z(.*\.) The default (value )?is    )	
isinstancer   ro   string_typesrematchr   DOTALLr   )ry   r   s     rA   r   FlagOrPositional._Scrub   sw     dllC$4$45588$dll33DLHH*D,<,<biiE Qd r@   )r)   r   r   r   r   r(   r*   r4   )	r:   r;   r<   r=   r>   rz   r   r?   __classcell__r   s   @rA   r~   r~      s    2( (r@   r~   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )Flagi
  zFlag info.

Attributes:
  choices: list|dict, The list of static choices.
  is_global: bool, True if the flag is global (inherited from the root).
  type: str, The flag value type name.
c                   > SSK Jn  [        [        U ]  X5        / U l        UR                  U l        UR                  S:X  a"  SU l        [        UR                  5      U l
        OUR                  [        L d  [        UR                  [        5      (       a  SU l        OUR                  [        L d  [        UR                  [        5      (       a  SU l        O[        UR                  UR                  5      (       a  SU l        O[[        UR                  UR                  5      (       a  SU l        O.[         R"                  " UR                  5      =(       d    SU l        UR
                  (       aj  [%        UR
                  5      nUS	S
/:X  a  SU l        OEUR
                  U l        ['        U[(        S 5      =n(       a  [%        U5      U R*                  [(        '   ['        U[,        S5      (       a  UR.                  U l        ['        U[0        S5      (       a  SU R*                  [0        '   ['        USS5      u  pgnU(       aK  [2        [4        R6                  " U5      0n	US:X  a  SUl        U(       a  X[8        '   XR*                  [:        '   g g )Nr   )arg_parsersboolintfloatdictliststringfalsetrueFTstore_property)NNN)rf   r   r   r   rz   r   r"   r*   r1   r   r   r   r   r   ArgDictArgListr	   r   sortedrx   LOOKUP_HIDDEN_CHOICESr   r   r)   LOOKUP_INVERTED_SYNOPSISLOOKUP_NAMEro   rp   LOOKUP_VALUELOOKUP_PROPERTY)ry   flagr(   r   r   r   propkindr4   r   r   s             rA   rz   Flag.__init__  s   3	$t*DL^^DN zzQdi$,,'dl	c	Zc::	99DLL%!@!@	dii!4!455	dii!4!455	--dii8DH	||t||$g	Wf%	%	||$T+@$GG>G-3N-C$)))
*t-u55#55dt-u55,0dii()&68JKD3==./d			"\#'ii  r@   )r)   r   r   r"   r1   r:   r;   r<   r=   r>   rz   r?   r   r   s   @rA   r   r   
  s    0( 0(r@   r   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )
PositionaliF  zPositional info.c                    > [         [        U ]  X5        SU l        UR                  c  SU l        UR                  S;  U l        g )NTr   )r   ?*z...)r   r   rz   r&   r*   r'   )ry   
positionalr(   r   s      rA   rz   Positional.__init__I  sA    	*d$Z6Ddj!''/CCDr@   )r&   r'   r*   r   r   s   @rA   r   r   F  s    D Dr@   r   c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )GroupiR  zMakes a constraint group from a command argument interceptor.

Attributes:
  arguments: [Argument], The list of arguments in the argument group.
c                 R   > [         [        U ]  U5        X l        SU l        X0l        g )NT)r   r   rz   _keyr#   r   )ry   r   keyr   r   s       rA   rz   Group.__init__Y  s#    	%&IDMNr@   )r   r   r#   NNr   r   s   @rA   r   r   R  s     r@   r   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )
Constrainti`  zArgument constraint group info.c                   > / nUR                    GH  nUR                  (       a*  [        U5      nUR                  UR                  U45        M?  UR
                  (       a:  UR                  R                  SS5      nUR                  S[        X55      45        M  UR                   Hs  nUR                  S5      (       d  M  UR                  SS5      n[        X55      nUR                   Vs/ s H  owU:w  d  M
  UPM     snUl        UR                  XV45        Mu     GM     [        US S9n[        [        U ]?  UU Vs/ s H  oS   PM	     snU(       a  US   S   OSS	9  g s  snf s  snf )
Nr   r   rk   --c                     U S   $ Nr   r8   )items    rA   <lambda>%Constraint.__init__.<locals>.<lambda>u  s    47r@   )r   r   r   )r   r   )r   r#   r   appendr   r&   destr   r   option_strings
startswithr   r)   r   r   rz   )
ry   r   orderrh   
constraintr(   r   altr   r   s
            rA   rz   Constraint.__init__c  s2   E	_
jooz23xxS)b*S/01&&D__T""<<S)D?D"11&1D[1&D" LL$& '   523E	*d$',-ut7u- E!HQKb % & .s   ,	E#9E#?E(
r8   r   r   s   @rA   r   r   `  s    ' r@   r   c                   *    \ rS rSrSrS rS rS rSrg)Commandi}  a  Command/group info.

Attributes:
  capsule: str, The first line of the command docstring.
  commands: {name:Command}, The subcommands in a command group.
  constraints: [Argument], Argument constraint tree.
  flags: {str:Flag}, Command flag dict, indexed by normalized flag name.
  is_global: bool, True if the command is the root command.
  is_hidden: bool, True if the command is hidden.
  is_group: bool, True if the command is a group.
  path: [str], The command path.
  is_auto_generated: bool, True if this command or group is auto-generated.
  universe_compatible: bool, True if the command is universe compatible.
  default_universe_compatible: bool, True if the command is compatible in the
    default universe.
  name: str, The normalized name ('_' => '-').
  positionals: [dict], Command positionals list.
  release: str, The command release name {'preview', 'alpha', 'beta', 'ga'}.
  sections: {str:str}, Section help dict, indexed by section name. At minimum
    contains the DESCRIPTION section.
c           	         SSK Jn  0 U l        0 U l        [	        U5      (       + U l        UR                  U l        UR                  5       U l        UR                  5       U l
        UR                  5       U l        UR                  5       U l        UR                  R!                  SS5      U l        UR#                  5       U l        / U l        UR)                  5       R*                  U l        0 U l        SR1                  U R$                  5      nU(       a  SR1                  UR$                  5      OSnU R3                  XR,                  [5        USS5      5      u  U l        n[7        U5      n0 nU R3                  XR,                  [5        USS5      5      u  U l        n[5        US	0 5      n	UR9                  U	5        [7        U5      nS
U;  a  XS
'   UR;                  5       n
U
(       a  XS'   U(       a_  [<        R>                  " U5       HE  u  pURA                  5       (       d  M  URC                  [7        U5      UUUUS9U R.                  U'   MG     URB                  " U4USR1                  U R$                  5      U R$                  (       a  U R$                  S   OSUS.UD6U l"        X l#        U(       a  XR                  U R                  '   URH                  nURJ                   H  nURL                   H  nURO                  S5      (       d  M  US:w  a  U RQ                  U5      (       a  M9  UR!                  SS5      n[S        X5      nURL                   Vs/ s H  nUU:w  d  M  UPM     snUl*        XR                  UR                  '   M     M     URV                   Hc  nURL                   HP  nURO                  S5      (       d  M  UR!                  SS5      n[S        X5      nXR                  UR                  '   MR     Me     URX                   HE  nURZ                  R!                  SS5      n[]        X5      nU R&                  R_                  U5        MG     [a        U5      U l1        g s  snf )Nr   )
console_ior   r    rk   
short_help	long_helpdetailed_helpDESCRIPTIONNOTES)commandindexr   parent_command.)r   man_nametop_commandr   r   z--help)2googlecloudsdk.core.consoler   r   r   r   r"   r#   IsHiddenr$   IsAutoGeneratedis_auto_generatedIsUniverseCompatibler2   IsDefaultUniverseCompatibler3   r(   r   GetPathr+   r,   ReleaseTrackidr.   r0   join_Command__Releaserx   rq   updateGetNotesHelpSectionro   	iteritemsisupper
LazyFormatr   _parentai	flag_argsr   r   _Command__Ancestorr   r)   ancestor_flag_argspositional_argsr   r   r   r   r   )ry   r   parentr   command_path_stringparent_path_stringr   r0   r   r   notesr(   contentsargsrh   r   r   r   s                     rA   rz   Command.__init__  s   6DMDJf%DN$$DM%%'DN$446D&;;=D'.'J'J'LD$$$S#.DI!DID''),,DLDM((499-28&++.b NNwwbADL' $G,GH $wwR@!DL+ G_b9MOOM"'4KH$ +}'')EwMM(3.$ <<>> * 5 5#H-)%/ !6 !$--
	 4 ((#$))$$(IIDIIaL2) DL L#'oodii ::D ~~$$$??4  X$//$"7"7c3'$c$ //$/c3$;c/$$
  #'**TYY
 %  &&$$$??4  c3'$c$"&**TYY
	 % ' ##XXc3'dc(j
j) $ "$'D)$s   
Q+$Q+c                 t    U R                   nU(       a%  XR                  ;   a  gUR                   nU(       a  M%  g)zDetermines if flag is provided by an ancestor command.

Args:
  flag: str, The flag name (no leading '-').

Returns:
  bool, True if flag provided by an ancestor command, false if not.
TF)r   r   )ry   r   r   s      rA   
__AncestorCommand.__Ancestor  s2     llG
		g ' r@   c                 r    [        U5      nUR                  5       n[        U5      S:  a  US   S:X  a  SnX#4$ )aI  Determines the release type from the description text.

Args:
  command: Command, The CLI command/group description.
  release: int, The default release type.
  description: str, The command description markdown.

Returns:
  (release, description): (int, str), The actual release and description
    with release prefix omitted.
   r   internalINTERNAL)rq   r   len)ry   r   r.   r   r+   s        rA   	__ReleaseCommand.__Release  s>     (4K??D
4yA~$q'Z/gr@   )r   r   r   r   r3   r   r   r"   r#   r$   r(   r+   r,   r.   r0   r2   N)	r:   r;   r<   r=   r>   rz   r   r   r?   r8   r@   rA   r   r   }  s    ,`(D  r@   r   c                   <   ^  \ rS rSrSrSU 4S jjrS rS rSrU =r	$ )CliTreeGeneratori  zGenerates an external representation of the gcloud CLI tree.

This implements the resource generator for gcloud meta list-gcloud.
c                 >   > [         [        U ]
  " USU0UD6  X l        g)z:branch is the command path of the CLI subtree to generate.cliN)r   r  rz   _branch)ry   r  branchr   kwargsr   s        rA   rz   CliTreeGenerator.__init__  s"    	
D*DDcDVDLr@   c                 H    U R                  U5      (       a  U$ [        X5      $ )a;  Visits each node in the CLI command tree to construct the external rep.

Args:
  node: group/command CommandCommon info.
  parent: The parent Visit() return value, None at the top level.
  is_group: True if node is a command group.

Returns:
  The subtree parent value, used here to construct an external rep node.
)_Pruner   )ry   noder   r#   s       rA   VisitCliTreeGenerator.Visit$  s#     {{4m4  r@   c                     U R                   (       d  gUR                  5       n[        U5      S:  a  gUSS nUS   S;   a  USS nU R                    H(  nU(       d    gUS   U:w  a    gUR                  S5        M*     g)a  Returns True if command should be pruned from the CLI tree.

Branch pruning is mainly for generating static unit test data. The static
tree for the entire CLI would be an unnecessary burden on the depot.

self._branch, if not None, is already split into a path with the first
name popped. If branch is not a prefix of command.GetPath()[1:] it will
be pruned.

Args:
  command: The calliope Command object to check.

Returns:
  True if command should be pruned from the CLI tree.
Fr  r   Nr   )alphabetapreviewT)r  r   r  pop)ry   r   r+   r(   s       rA   r  CliTreeGenerator._Prune3  s}    " <<??D
4y1}8DAw..!"Xd	aD
hhqk  r@   )r  r   )
r:   r;   r<   r=   r>   rz   r  r  r?   r   r   s   @rA   r  r    s    

!$ $r@   r  SERIALIZED_FLAG_LISTc                 j  ^^^^^	^
 [        U [        S5      (       a  U $ 0 m
 " S S[        5      mS mUUUU
4S jmT" U 5        / n[        [	        T
5      5       H+  u  p#T
U   nX$l        UR                  UR                  5        M-     UUU
4S jmUUU	U
4S jm	T	" U 5        [        U [        U5        U $ )a  Returns the CLI tree optimized for serialization.

Serialized data does not support pointers. The CLI tree can have a lot of
redundant data, especially with ancestor flags included with each command.
This function collects the flags into the _LOOKUP_SERIALIZED_FLAG_LIST array
in the root node and converts the flags dict values to indices into that
array.

Serialization saves a lot of space and allows the ancestor flags to be
included in the LOOKUP_FLAGS dict of each command. It also saves time for
users of the tree because the LOOKUP_FLAGS dict also contains the ancestor
flags.

Apply this function to the CLI tree just before dumping. For the 2017-03
gcloud CLI with alpha and beta included and all ancestor flags included in
each command node this function reduces the generation time from
~2m40s to ~35s and the dump file size from 35Mi to 4.3Mi.

Args:
  tree: The CLI tree to be optimized.

Returns:
  The CLI tree optimized for serialization.
Nc                       \ rS rSrSrS rSrg)_Serialize.<locals>._FlagIndexi}  zFlag index + definition.c                     Xl         SU l        g r   r   r   )ry   r   s     rA   rz   '_Serialize.<locals>._FlagIndex.__init__  s    idjr@   r#  Nr|   r8   r@   rA   
_FlagIndexr!  }  s
    "r@   r%  c                 
   SR                  [        R                  " U R                  5      SR	                  SR                  S U R
                   5       5      5      [        R                  " U R                  5      [        R                  " U R                  5      SR	                  SR                  S U R                   5       5      5      [        R                  " U R                  5      [        R                  " U R                  5      [        R                  " U R                  5      [        R                  " U R                  5      [        R                  " U R                  5      [        R                  " U R                  5      [        R                  " U R                  5      [        R                  " U R                   5      [        R                  " U R"                  5      [        R                  " U R$                  5      /5      $ )Nz::z[{}]z, c              3   N   #    U  H  n[         R                  " U5      v   M     g 7fNro   rp   ).0ns     rA   	<genexpr>4_Serialize.<locals>._FlagIndexKey.<locals>.<genexpr>  s     G0F1cmmA&&0F   #%c              3   N   #    U  H  n[         R                  " U5      v   M     g 7fr(  r)  )r*  cs     rA   r,  r-    s     G,Qa 0 0,r.  )r   ro   rp   r(   formatr)   r   r   r   r   r   r   r$   r"   r#   r'   r*   r1   r4   )r   s    rA   _FlagIndexKey!_Serialize.<locals>._FlagIndexKey  s1   99dii IIG0F0FGG	
 	dii dmm$diiG$,,GGHdnn%dll#d&&'dnn%dnn%dmm$d&&'djj!dii djj!#  r@   c                    > U R                   R                  5        H  nT" U5      TT" U5      '   M     U R                  R                  5        H  nT" U5        M     g r(  )r   valuesr   )r   r   
subcommand_CollectAllFlagsr%  r2  	all_flagss      rA   r7  $_Serialize.<locals>._CollectAllFlags  sO    $$&'1$'7id#$ '&&--/
z" 0r@   c                 4  > Sn[        U 5       Hu  u  p#[        U[        5      (       a  M  UR                  (       a  T" UR                  5        MA  UR
                  (       a  US-  nXU'   M]   TT" U5         R                  X'   Mw     g ! [         a     M  f = f)Nr   r   )	enumerater   r   r#   r   r&   r   r_   )r   positional_indexirh   r2  _ReplaceConstraintFlagWithIndexr8  s       rA   r>  3_Serialize.<locals>._ReplaceConstraintFlagWithIndex  s    I&	C		<<'6A'!	"=#56<<), '  	
	s   -B		
BBc                 &  > [         R                  " U R                  5       HC  u  pTT" U5         R                  U R                  U'   T" U R                  R
                  5        ME     U R                  R                  5        H  nT" U5        M     g r(  )ro   r   r   r   r   r   r   r5  )r   r(   r   r6  r2  r>  _ReplaceFlagWithIndexr8  s       rA   rA  )_Serialize.<locals>._ReplaceFlagWithIndex  sq    mmGMM2
%mD&9:@@gmmD%g&9&9&C&CD 3 &&--/
J' 0r@   )	rx   _LOOKUP_SERIALIZED_FLAG_LISTobjectr;  r   r   r   r   setattr)treeall_flags_listr   r   fir7  r%  r2  r>  rA  r8  s        @@@@@@rA   
_SerializerI  ]  s    4 T/66K )6 *# # 4
 .fY/0je	3BH"''" 1 ( ( 	$,n=	+r@   c                 n    SSK Jn  SSK Jn  UR                  UR	                  [        U 5      5      SUS9  g)zDump helper.r   )resource_printerresource_projectorjson)outN)googlecloudsdk.core.resourcerK  rM  PrintMakeSerializablerI  )rF  frK  rM  s       rA   _DumpToFilerT    s2    ;=))*T*:;V  r@   c                  2   [         R                  " 5       n U R                  c  [        S5      e[        R
                  R                  U R                  SS5      n[        R
                  R                  U5      (       d  [        SR                  U5      5      eU$ )a<  The CLI tree default directory.

This directory is part of the installation and its contents are managed
by the installer/updater.

Raises:
  SdkRootNotFoundError: If the SDK root directory does not exist.
  SdkDataCliNotFoundError: If the SDK root data CLI directory does not exist.

Returns:
  The directory path.
zQSDK root not found for this installation. CLI tree cannot be loaded or generated.datar  ziSDK root data CLI directory [{}] not found for this installation. CLI tree cannot be loaded or generated.)
r   Pathssdk_rootrF   osr+   r   isdirrL   r1  )paths	directorys     rA   
CliTreeDirr]    s~     ,,.%
^^
	  ggll5>>659)	y	!	!
!	228&2C  
r@   c                  r   [         R                  " 5       R                  n [        R                  R                  U S5      n[        R                  R                  U 5      (       a;  [        R                  R                  U5      (       d  [        R                  " USS9  U$ [        SR                  U 5      5      e)a
  Returns the CLI tree config directory.

This directory is part of the user config directory its contents are stable
across releases/installations/updates.

Raises:
  SdkConfigNotFoundError: If the SDK config directory does not exist.

Returns:
  The directory path.
r  T)exist_okzbCLI config directory [{}] not found for this installation. CLI tree cannot be loaded or generated.)
r   rW  global_config_dirrY  r+   r   rZ  makedirsrI   r1  )r`  cli_tree_config_dirs     rA   CliTreeConfigDirrc    s     lln66%6>WW]]$%%77==,--kk%5 
	 !	228&9J2K r@   c                 j    [         R                  R                  U=(       d
    [        5       U S-   5      $ )zFReturns the CLI tree file path for name, default if directory is None..json)rY  r+   r   r]  r(   r\  s     rA   CliTreePathrg  
  s"    	i/:<	@@r@   c                 j    [         R                  R                  U=(       d
    [        5       U S-   5      $ )zMReturns the CLI tree config file path for name, default if directory is None.re  )rY  r+   r   rc  rf  s     rA   CliTreeConfigPathri    s$    	i5#3#5tg~	FFr@   c                 v   SSK Jn  US:X  a  SR                  U5      nO*U(       a  SR                  X!5      nOSR                  U5      nUR                  U5         [	        XS9R                  SS	9n[        U[        [        5        [        U[        [        5       5        UsS
S
S
5        $ ! , (       d  f       g
= f)z,Generates and returns the CLI root for name.r   )progress_trackerr   zGenerating the {} CLIz)Generating the {} CLI and caching in [{}]z4Generating the {} CLI for one-time use (no SDK root))r  T)rv   N)r   rk  r1  ProgressTrackerr  WalkrE  LOOKUP_VERSIONr   LOOKUP_CLI_VERSIONrc   )r  r+   r(   r  rk  messagerF  s          rA   _GenerateRootrq    s    :	S[%,,T2G9@@LGDKKG ''0C/44D4ADD.'*D$&B&DE	 100s   AB**
B8c                    Uc
  [        5       n[        XX#S9nUS:X  a  [        U[        R                  5        O*[
        R                  " U5       n[        XE5        SSS5        SSKJn  UR                  U5      $ ! , (       d  f       N%= f)au  Dumps the CLI tree to a JSON file.

The tree is processed by cli_tree._Serialize() to minimize the JSON file size
and generation time.

Args:
  cli: The CLI.
  path: The JSON file path to dump to, the standard output if '-', the default
    CLI tree path if None.
  name: The CLI name.
  branch: The path of the CLI subtree to generate.

Returns:
  The generated CLI tree.
N)r  r+   r(   r  r   r   rL  )
ri  rq  rT  sysstdoutr
   
FileWriterrP  rM  rR  )r  r+   r(   r  rF  rS  rM  s          rA   Dumprv  '  sl      
\D	3	D$	S[cjj!			$	1$ 
 =		,	,T	22	 
 	s   A::
Bc                    [         nU R                  [        5      nXT:w  a#  U(       d  [        SR	                  XU5      5      eg[        5       nU R                  [        5      n[        [        4nXx;   d  Xh;   a  O(Xv:w  a#  U(       d  [        SR	                  XU5      5      egU(       a5  SSK	J
n	  U	R                  R                  SR	                  [        U5      5        g)a  Returns True if the CLI tree on path is up to date.

Args:
  tree: The loaded CLI tree.
  path: The path tree was loaded from.
  ignore_errors: If True then return True if tree versions match. Otherwise
    raise exceptions on version mismatch.
  verbose: Display a status line for up to date CLI trees if True.

Raises:
  CliTreeVersionError: tree version mismatch.
  CliCommandVersionError: CLI command version mismatch.

Returns:
  True if tree versions match.
z,CLI tree [{}] version is [{}], expected [{}]Fz4CLI tree [{}] command version is [{}], expected [{}]r   )logz)[{}] CLI tree version [{}] is up to date.T)r   getrn  rC   r1  rc   ro  r[   rY   googlecloudsdk.corerx  statusrQ  DEFAULT_CLI_NAME)
rF  r+   ignore_errorsverboseexpected_tree_versionactual_tree_versionexpected_command_versionactual_command_versiontest_versionsrx  s
             rA   _IsUpToDater  D  s    $ "01"
8
?
?)> 
 9;88$67(*?@--	!	29"
@
G
G,D 
 'JJ3::6	

 
r@   c                     U(       dH  [         R                  " [        R                  " U 5      5      n[	        X@[        U5      U5      (       a  U$ A [        R                  " U 5        g! [         a     gf = f! [        R                   a0  nU(       d  [        [        R                  " U5      5      e SnAgSnAff = f)zALoad() helper. Returns a tree or None if the tree failed to load.N)rN  loadsr
   ReadFileContentsr  r   rY  removeOSErrorr6   rR   ro   rp   )r+   r  forcer~  rF  es         rA   _Loadr  }  s    /ZZ..t45d	TcG	4	4
iio 
  
 
	 /S]]1-.. 	/s<   AA9 A9 A) )
A63A9 5A66A9 9B=&B88B=c                    ^^^ U R                  [        5      mT(       d  U $ SU [        '   U [        	 UU4S jmUUU4S jmT" U 5        U $ )z5Returns the deserialization of a serialized CLI tree.Nc                    > [        U 5       Hn  u  p#[        U[        5      (       a  US:  a  XS-   *    X'   M,  TU   X'   M5  UR                  [        S5      (       d  MR  T" UR                  [
        5      U5        Mp     g )Nr   r   F)r;  r   r   ry  LOOKUP_IS_GROUPLOOKUP_ARGUMENTS)r   r,   r=  rh   '_ReplaceConstraintIndexWithArgReferencerG  s       rA   r  =_Deserialize.<locals>._ReplaceConstraintIndexWithArgReference  sl    I&	C		7$QwZ0),',),77?E**/GG$%{	
 'r@   c                    > U [            n[        R                  " U5       H  u  p#TU   X'   M     U [           [           nT" X@[
           5        U [           R                  5        H  nT" U5        M     g r(  )LOOKUP_FLAGSro   r   LOOKUP_CONSTRAINTSr  LOOKUP_POSITIONALSLOOKUP_COMMANDSr5  )	r   r   r(   r   r   r6  r  _ReplaceIndexWithFlagReferencerG  s	         rA   r  4_Deserialize.<locals>._ReplaceIndexWithFlagReference  sr    L!E}}U+"5)ek ,*+,<=I+-. o.557
$Z0 8r@   )ry  rC  )rF  r  r  rG  s    @@@rA   _Deserializer    sG    8889.	K'+$#$
'(

	1 !&	+r@   c                     U c   [        5       n [        XX$S9nU(       d  [        XS9  [        U 5      n[        U5      $ ! [         a4    U(       a+  U(       a$  SSKJn  [	        U5      nUR                  U5      s $ e f = f)a  Loads the default CLI tree from the json file path.

Args:
  path: The path name of the JSON file the CLI tree was dumped to. None for
    the default CLI tree path.
  cli: The CLI. If not None and path fails to import, a new CLI tree is
    generated, written to path, and returned.
  force: Update an existing tree by forcing it to be out of date if True.
  one_time_use_ok: If True and the load fails then the CLI tree is generated
    on the fly for one time use.
  verbose: Display a status line for up to date CLI trees if True.

Raises:
  CliTreeVersionError: loaded tree version mismatch
  CliTreeLoadError: load errors

Returns:
  The CLI tree.
r   rL  )r  r  r~  )r  r+   )	ri  rI   rP  rM  rq  rR  r  rv  r  )r+   r  r  one_time_use_okr~  rM  rF  s          rA   Loadr    sz    , 
\ d 
tE	;$	S;D	d	 " 	CS!!22488s   
? :A=;A=c                 .   / nU (       a)  UR                  U 5        U(       d  SR                  U 5      n[        S[        U=(       d    0 [        U=(       d    0 [
        U=(       d    0 [        S[        S[        U[        U=(       d    0 [        S[        SU00
$ )z)Creates and returns a CLI tree node dict.zThe {} command.rk   TFGAr   )r   r1  LOOKUP_CAPSULEr  r  r  r  LOOKUP_IS_HIDDENLOOKUP_PATHr  LOOKUP_RELEASELOOKUP_SECTIONS)r   r   r   r   r+   r,   r   s          rA   Noder    s~     
$KK%,,W5kbx~2++EKRt4++d{3
 r@   )NFF)NNFFF)NNNNNNN)`r>   
__future__r   r   r   rN  rY  r   rs  rm   rf   r   rz  r   r   r	   googlecloudsdk.core.utilr
   ro   r   r|  CLI_VERSION_READONLYCLI_VERSION_UNKNOWNr[   rY   r  ro  rn  LOOKUP_ATTRr  r   LOOKUP_CHOICESr   r  r   r  LOOKUP_DEFAULTLOOKUP_DESCRIPTIONr  LOOKUP_GROUPLOOKUP_GROUPSr   LOOKUP_IS_GLOBALr  r  LOOKUP_IS_MUTEXLOOKUP_IS_POSITIONALLOOKUP_IS_REQUIREDr   r   LOOKUP_NARGSr  r  r   r  LOOKUP_REQUIREDr  LOOKUP_TYPELOOKUP_UNIVERSE_COMPATIBLE"LOOKUP_DEFAULT_UNIVERSE_COMPATIBLEr   r6   rC   rF   rI   rL   rO   rR   rU   rc   ri   rq   rD  rs   r~   r   r   r   r   r   Walkerr  rC  rI  rT  r]  rc  rg  ri  rq  rv  r  r  r  r  r  r8   r@   rA   <module>r     s    C &  '  	 	 
  * & * + * 
   "  
    " (  " " .   & " . " 2 %B "(J (6U 6)5 )3U 35e 5*% *u 
,'* 'v '0<(x <(~9( 9(x	D! 	DH  :Y f Y x>v}} >B  6 k\82 & A
 ,t G
 !'7 & .t 3:6r&"L FK(X 
	r@   