
                             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K	J
r
  SSK	Jr  SS
 jr " S S\5      r " S S\R                  5      rSS jrg	)zACoverage tree generator. Used for flag coverage kokoro presubmit.    )absolute_import)division)unicode_literals)walker)progress_tracker)resource_printer)resource_projectorNc           	          [         R                  " S5         [        R                  " [	        XUS9R                  5       5      sSSS5        $ ! , (       d  f       g= f)a  Generates and returns the static completion CLI tree.

Args:
  cli: The CLI.
  branch: The path of the CLI subtree to generate.
  restrict: The paths in the tree that we are allowing the tree to walk under.

Returns:
  Returns the serialized static completion CLI tree.
z&Generating the flag coverage CLI tree.)restrictN)r   ProgressTrackerr	   MakeSerializableCoverageTreeGeneratorWalkclibranchr   s      8lib/googlecloudsdk/command_lib/flag_coverage/generate.pyGenerateCoverageTreer      sG     ''.0..cH=BBDF0 0 0s   ,A
Ac                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )CoverageCommandNode-   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                   > [         [        U ]  5         X l        Ub   UR                  R                  SS5      nXU'   UR                  nUR                   Hg  nUR                   HT  nUR                  (       a  M  UR                  S5      (       d  M.  U R                  U5      (       a  MF  UR                  X'   MV     Mi     g )N_-z--)superr   __init___parentnamereplaceai	flag_argsoption_strings	is_hidden
startswithIsAncestorFlagrequire_coverage_in_tests)selfcommandparentr   argsarg	__class__s         r   r   CoverageCommandNode.__init__6   s    	
t-/L\\!!#s+dTl::D~~$$$==
t$$
t$$
22
 %     c                 `    U R                   nU(       a  X;   a  gUR                   nU(       a  M  g)a3  Determines if flag is provided by an ancestor command.

NOTE: This function is used to allow for global flags to be added in at the
      top level but not in subgroups/commands
Args:
  flag: str, The flag name (no leading '-').

Returns:
  bool, True if flag provided by an ancestor command, false if not.
TFr   )r'   flagr(   s      r   r%   "CoverageCommandNode.IsAncestorFlagJ   s-     llG
	g ' r.   r0   )	__name__
__module____qualname____firstlineno____doc__r   r%   __static_attributes____classcell__r,   s   @r   r   r   -   s    3( r.   r   c                   6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )r   ]   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.)r   r   N)r   r   r   _branch)r'   r   r   r   r,   s       r   r   CoverageTreeGenerator.__init__`   s    	
/C/KLr.   c                     [        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.
)r   )r'   noder)   is_groups       r   VisitCoverageTreeGenerator.Visite   s     t,,r.   )r>   NNN)	r3   r4   r5   r6   r7   r   rC   r8   r9   r:   s   @r   r   r   ]   s    8
- -r.   r   c                 F    [        XUS9n[        R                  " USUS9  U$ )aF  Lists the flag coverage 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.
  restrict: The paths in the tree that we are allowing the tree to walk under.

Returns:
  Returns the serialized coverage CLI tree.
r   json)print_formatout)r   r   Print)r   r   rI   r   trees        r   OutputCoverageTreerL   s   s'     
#x	H$F<	+r.   )NNrE   )r7   
__future__r   r   r   googlecloudsdk.callioper   googlecloudsdk.core.consoler   googlecloudsdk.core.resourcer   r	   r   dictr   Walkerr   rL    r.   r   <module>rT      sH     H &  ' * 8 9 ;F"-$ -`-FMM -,r.   