
    7                         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	r	 " S	 S
\
5      r " S S\
5      rS rg)zClasses that manage concepts and dependencies.

For usage examples, see
googlecloudsdk/command_lib/concepts/all_concepts/base.py.
    )absolute_import)division)unicode_literals)base)dependency_managers)namesNc                   0    \ rS rSrSrS rS rS rS rSr	g)	ConceptManager!   az  A manager that contains all concepts (v2) for a given command.

This object is responsible for registering all concepts, creating arguments
for the concepts, and creating a RuntimeParser which will be responsible
for parsing the concepts.

Attributes:
  concepts: [base.Concept], a list of concepts.
  runtime_parser: RuntimeParser, the runtime parser manager for all concepts.
c                 .    / U l         S U l        0 U l        g )N)conceptsruntime_parser_command_level_fallthroughsselfs    ;lib/googlecloudsdk/command_lib/concepts/concept_managers.py__init__ConceptManager.__init__-   s    DMD')D$    c                 :    U R                   R                  U5        g)zAdd a single concept.

This method adds a concept to the ConceptManager. It does not immediately
have any effect on the command's argparse parser.

Args:
  concept: base.Concept, an instantiated concept.
N)r   append)r   concepts     r   
AddConceptConceptManager.AddConcept2   s     	MM!r   c                     U R                    Vs/ s H  o"R                  5       PM     nnU R                  X15        [        U5      U l        UR                  U R                  5        gs  snf )a  Adds concept arguments and concept RuntimeParser to argparse parser.

For each concept, the Attribute() method is called, and all resulting
attributes and attribute groups are translated into arguments for the
argparse parser.

Additionally, a concept-specific RuntimeParser is created with all of the
resulting attributes from the first step. (This will be responsible for
parsing the concepts.) It is registered to the argparse parser, and will
appear in the final parsed namespace under CONCEPT_ARGS.

Args:
  parser: googlecloudsdk.calliope.parser_arguments.ArgumentInterceptor, the
    argparse parser to which to add argparse arguments.
N)r   	Attribute_AddToArgparseRuntimeParserr   add_concepts)r   parserr   
attributess       r   AddToParserConceptManager.AddToParser=   sX      6:]]C]'##%]JC
+'
3D
++, Ds   A'c                 J   U H  n[        U[        R                  5      (       a)  UR                  " UR                  40 UR
                  D6  MK  UR                  " UR
                  R                  S5      40 UR
                  D6nU R                  UR                  U5        M     g)z0Recursively add an arg definition to the parser.helpN)

isinstancer   r   add_argumentarg_namekwargsadd_argument_grouppopr   r!   )r   r!   r    	attributegroups        r   r   ConceptManager._AddToArgparseR   s    		It~~	.	.I..C)2B2BC''	(8(8(<(<V(D <*3*:*:<e
)..6  r   )r   r   r   N)
__name__
__module____qualname____firstlineno____doc__r   r   r"   r   __static_attributes__ r   r   r
   r
   !   s    	*
	"-*7r   r
   c                   *    \ rS rSrSrS rS rS rSrg)r   ]   a  An object to manage parsing all concepts via their attributes.

Once argument parsing is complete and ParseConcepts is called, each parsed
concept is stored on this runtime parser as an attribute, named after the
name of that concept.

Attributes:
  parsed_args: the argparse namespace after arguments have been parsed.
  <CONCEPT_NAME> (the namespace format of each top level concept, such as
    "foo_bar"): the parsed concept corresponding to that name.
c                     S U l         0 U l        U Hh  n[        R                  " UR                  R                  5       5      nX0R                  ;   a  [        SR                  U5      5      eX R                  U'   Mj     g )NzDAttempting to add two concepts with the same presentation name: [{}])parsed_args_attributesr   ConvertToNamespaceNamer   GetPresentationName
ValueErrorformat)r   r!   r,   	attr_names       r   r   RuntimeParser.__init__j   sv    DD	..



/
/
13i	&&	& 3396)3DF 	F$-y!  r   c                 0   0 n[         R                  " U R                  5       H;  u  p#[        R                  R                  U5      n[        X@R                  5      X'   M=     [         R                  " U5       H  u  pV[        U R                  XV5        M     g)a  Parse all concepts.

Stores the result of parsing concepts, keyed to the namespace format of
their presentation name. Afterward, will be accessible as
args.<LOWER_SNAKE_CASE_NAME>.

Raises:
  googlecloudsdk.command_lib.concepts.exceptions.Error: if parsing fails.
N)
six	iteritemsr:   r   DependencyNodeFromAttribute
FinalParse
ParsedArgssetattrr9   )r   finalr?   r,   dependenciesnamevalues          r   ParseConceptsRuntimeParser.ParseConceptsu   st     E #d.>.> ?	(77EEiPl#L//Be !@ }}U+d, ,r   c                     U R                   $ )zA lazy property to use during concept parsing.

Returns:
  googlecloudsdk.calliope.parser_extensions.Namespace: the parsed argparse
    namespace | None, if the parser hasn't been registered to the namespace
    yet.
)r9   r   s    r   rG   RuntimeParser.ParsedArgs   s     r   )r:   r9   N)	r/   r0   r1   r2   r3   r   rM   rG   r4   r5   r   r   r   r   ]   s    
	.-0r   r   c                 ^    [         R                  " U 5      nU" 5       nUR                  U5      $ )as  Lazy parser stored under args.CONCEPT_ARGS.

Args:
  dependencies: dependency_managers.DependencyNode, the root of the tree of
    the concept's dependencies.
  arg_getter: Callable, a function that returns the parsed args namespace.

Raises:
    googlecloudsdk.command_lib.concepts.exceptions.Error: if parsing fails.

Returns:
  the result of parsing the root concept.
)r   DependencyManagerParseConcept)rJ   
arg_getterdependency_managerr9   s       r   rF   rF      s-     +<<\J+		(	(	55r   )r3   
__future__r   r   r   #googlecloudsdk.command_lib.conceptsr   r   r   rB   objectr
   r   rF   r5   r   r   <module>rY      s@     '  ' 4 C 5 
97V 97x8F 8v6r   