
                             S r SSKJr  SSKJr  SSKJ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\5      r " S S\R                  5      rSS jrSS jrg)z%Static completion CLI tree generator.    )absolute_import)division)unicode_literalsN)walker)progress_tracker)resource_printer)resource_projectorc                   *    \ rS rSrSrS rS rS rSrg)_Command   zCommand/group info.

Attributes:
  commands: {str:_Command}, The subcommands in a command group.
  flags: [str], Command flag list. Global flags, available to all commands,
    are in the root command flags list.
c                    0 U l         0 U l        X l        U(       a*  UR                  R	                  SS5      nXR                   U'   UR
                  nUR                   Hj  nUR                   HW  nUR                  (       a  M  UR                  S5      (       d  M.  U R                  U5      (       a  MF  U R                  XS5        MY     Ml     UR                   Hc  nUR                   HP  nUR                  (       d  UR                  (       a  M'  UR                  S5      (       d  M?  U R                  XS5        MR     Me     g )N_-z--)commandsflags_parentnamereplaceai	flag_argsoption_strings	is_hidden
startswith_Command__Ancestor_Command__AddFlagancestor_flag_args	is_global)selfcommandparentr   argsargs         <lib/googlecloudsdk/command_lib/static_completion/generate.py__init___Command.__init__'   s    DMDJ L\\!!#s+d"ood::D ~~$$$==
t$$
??4  
s! %  &&$$$==CMM
t$$
s! % '    c                   ^ SnUR                   (       a7  [        US/ 5      m[        U4S jUR                    5       5      nUSS/:X  a  SnO&UR                  S:w  a  [        USS 5      (       a  SOS	nX0R                  U'   g )
Nboolhidden_choicesc              3   6   >#    U  H  oT;  d  M
  Uv   M     g 7f)N ).0cr)   s     r#   	<genexpr>%_Command.__AddFlag.<locals>.<genexpr>L   s     J,Q>2Iqq,s   		falsetruer   	completerdynamicvalue)choicesgetattrsortednargsr   )r   flagr   r5   r)   s       @r#   	__AddFlag_Command.__AddFlagH   sq    G||t%5r:nJ$,,JJg	Wf%	%	q$T;==	7gJJtr&   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   )r   r9   r   s      r#   
__Ancestor_Command.__AncestorS   s2     llG
		g ' r&   )r   r   r   N)	__name__
__module____qualname____firstlineno____doc__r$   r   r   __static_attributes__r+   r&   r#   r   r      s    "B	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	$ )_CompletionTreeGeneratord   z0Generates the gcloud static completion CLI tree.c                 4   > [         [        U ]  XS9  X l        g)z:branch is the command path of the CLI subtree to generate.)cliignore_load_errorsN)superrF   r$   _branch)r   rI   branchrJ   	__class__s       r#   r$   !_CompletionTreeGenerator.__init__g   s     	
"D2 3 8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   )r   noder    is_groups       r#   Visit_CompletionTreeGenerator.Visitm   s#     {{4mD!!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.
F      Nr   )alphabetaT)rL   GetPathlenpop)r   r   pathr   s       r#   rQ   _CompletionTreeGenerator._Prune|   s}    " <<??D
4y1}8DAw##!"Xd	aD
hhqk  r&   )rL   )NNF)
r?   r@   rA   rB   rC   r$   rT   rQ   rD   __classcell__)rN   s   @r#   rF   rF   d   s    8"$ $r&   rF   c           	          [         R                  " S5         [        R                  " [	        XUS9R                  5       5      sSSS5        $ ! , (       d  f       g= f)zGenerates and returns the static completion CLI tree.

Args:
  cli: The CLI.
  branch: The path of the CLI subtree to generate.
  ignore_load_errors: Ignore CLI tree load errors if True.

Returns:
  Returns the serialized static completion CLI tree.
z*Generating the static completion CLI tree.)rM   rJ   N)r   ProgressTrackerr	   MakeSerializablerF   Walk)rI   rM   rJ   s      r#   GenerateCompletionTreere      sJ     ''24.. 3E	GGKtvO4 4 4s   ,A
Ac                     [        XS9nU=(       d    [        R                  R                  S5        [        R
                  " USUS9  U$ )a  Lists the static completion CLI tree as a Python module file.

Args:
  cli: The CLI.
  branch: The path of the CLI subtree to generate.
  out: The output stream to write to, sys.stdout by default.

Returns:
  Returns the serialized static completion CLI tree.
)rI   rM   z# -*- coding: utf-8 -*- #
"""Cloud SDK static completion CLI tree."""
# pylint: disable=line-too-long,bad-continuation
STATIC_COMPLETION_CLI_TREE = json)print_formatout)re   sysstdoutwriter   Print)rI   rM   ri   trees       r#   ListCompletionTreero      sC     
 C	7$#** ! "
 F<	+r&   )NF)NN)rC   
__future__r   r   r   rj   googlecloudsdk.callioper   googlecloudsdk.core.consoler   googlecloudsdk.core.resourcer   r	   objectr   WalkerrF   re   ro   r+   r&   r#   <module>rv      sM     , &  ' 
 * 8 9 ;Cv CL<v}} <~O$r&   