
                             d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddl	mZ dd
Z G d de      Z G d dej                        ZddZy	)zACoverage tree generator. Used for flag coverage kokoro presubmit.    )absolute_import)division)unicode_literals)walker)progress_tracker)resource_printer)resource_projectorNc                     t        j                  d      5  t        j                  t	        | ||      j                               cddd       S # 1 sw Y   yxY w)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      sI     ''.0..c6H=BBDF0 0 0s   /AAc                   (     e Zd ZdZ fdZd Z xZS )CoverageCommandNodezCommand/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                 Z   t         t        |           || _        |!|j                  j                  dd      }| ||<   |j                  }|j                  D ]S  }|j                  D ]B  }|j                  r|j                  d      s"| j                  |      r4|j                  | |<   D U y )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   zCoverageCommandNode.__init__6   s    	
t-/DL\\!!#s+dfTl::D~~$$$==
t$
t$
22T
 %     c                 H    | j                   }|r||v ry|j                   }|ry)aO  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$   z"CoverageCommandNode.IsAncestorFlagJ   s-     llG
	g  r,   )__name__
__module____qualname____doc__r   r$   __classcell__r+   s   @r   r   r   -   s    3(r,   r   c                   *     e Zd ZdZd fd	Zd Z xZS )r   z0Generates the gcloud static completion CLI tree.c                 >    t         t        |   ||       || _        y)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   zCoverageTreeGenerator.__init__`   s    	
/C(/KDLr,   c                     t        ||      S )aW  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   VisitzCoverageTreeGenerator.Visite   s     tV,,r,   NNN)r/   r0   r1   r2   r   r;   r3   r4   s   @r   r   r   ]   s    8
-r,   r   c                 R    t        | ||      }t        j                  |d|       |S )aV  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   r@   r   trees        r   OutputCoverageTreerC   s   s)     
#fx	H$F<	+r,   )NNr<   )r2   
__future__r   r   r   googlecloudsdk.callioper   googlecloudsdk.core.consoler   googlecloudsdk.core.resourcer   r	   r   dictr   Walkerr   rC    r,   r   <module>rK      sH     H &  ' * 8 9 ;F"-$ -`-FMM -,r,   