
    h-                        S 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
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 r  SS jr " S S\R0                  5      r " S S\R4                  5      rg)z&The meta cache completers run command.    N)arg_parsers)base)parser_extensions)
cache_util)parameter_info_lib)concept_parsers)presentation_specs)
exceptions)log)module_util)
console_ioc                   *    \ rS rSrSrS rS rS rSrg)_FunctionCompleter$   zEConvert an argparse function completer to a resource_cache completer.c                     Xl         S U l        g N
_completer
parameters)self	completers     (lib/surface/meta/cache/completers/run.py__init___FunctionCompleter.__init__'   s    ODO    c                     AU$ r    )r   parsed_argsarguments      r   ParameterInfo _FunctionCompleter.ParameterInfo+   s    r   c                      U R                  XS9$ )N)r   )r   )r   prefixparameter_infos      r   Complete_FunctionCompleter.Complete/   s    ??6?>>r   r   N)	__name__
__module____qualname____firstlineno____doc__r   r    r%   __static_attributes__r   r   r   r   r   $   s    M?r   r   c                    [         R                  " U 5      n[        U5      (       a  U" 5       nUR                  SS5      nUR	                  S5       Vs0 s H;  nU(       d  M  UR	                  S5      S   SU;   a  UR	                  S5      S   OS_M=     nnUR                  SS5      n[
        R                  " UR                  S	UR                  5      US
4UUS.UD6$ s  snf )zBuild a presentation spec.flag_name_overrides ;:r      prefixesFnamez	help text)r.   r3   )r   ImportModulecallablepopsplitr	   ResourcePresentationSpecr4   )resource_spec_pathkwargsresource_specr.   or3   s         r   _GetPresentationSpecr>   3   s    **+=>-m!OM

#8"= #((--!	
 ;aggcl1o#(qwws|A:-   ZZ
E*(		4	4jj++,
 .
 	
 s   C"3Cc                 R   U=(       d    0 nU(       a4  [        U40 UD6n[        R                  " U 5      " UR                  U5      nO6[        R                  " U 5      n[	        U[
        5      (       d  [        U5      $  U" SUUS.UD6$ ! [         a    [        U" 5       5      s $ f = f)z2Returns an instantiated completer for module_path.)cachequalified_parameter_namesr   )r>   r   r5   concept_spec
isinstancetyper   	TypeError)	module_pathr@   qualifyr<   presentation_kwargs	attributer;   presentation_specr   s	            r   _GetCompleterrK   G   s     ,1r,] D/BD((5&&I
 ((5Ii&&	**+ ")   
 +ik**+s   >
B	 	B&%B&c                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )AddCompleterResourceFlags`   z4Adds resource argument flags based on the completer.c                 J   > [         [        U ]
  " U0 UD6  S U l        S U l        g r   )superrM   r   $_AddCompleterResourceFlags__argument%_AddCompleterResourceFlags__completer)r   argsr;   	__class__s      r   r   "AddCompleterResourceFlags.__init__c   s'    	
#T3TDVDDODr   c           
         / nUR                   =(       d    0 nUR                  (       a  [        UR                  40 UD6n[        R                  " U/5      R                  UR                  5      nUR                  5        Hf  nUR                  R                  S5      (       a  SUR                  S'   O"UR                  (       d  SOSUR                  S'   UR                  U5        Mh     UR                  =(       d    0 n[        U4UR                  UR                  UUR                  S.UD6U l        U R                  R                   (       a  U R                  R                    H  n	["        R$                  " U	R                  5      n
['        X5      (       a  M5  ["        R(                  " U
5      n[*        R,                  " UU
SS	R/                  U R                  R0                  R2                  U	R                  5      S
9nUR                  U5        M     [*        R,                  " SSSS9U l        UR                  U R4                  5        U$ )Nz--Frequired?*nargs)rG   r<   rH   rI   zRESOURCE COMPLETERz{} `{}` parameter value.)destcategoryhelpresource_to_completezThe partial resource name to complete. Omit to enter an interactive loop that reads a partial resource name from the input and lists the possible prefix matches on the output or displays an ERROR message.)rZ   r]   )resource_presentation_kwargsr:   r>   r   ConceptParserGetInfor4   GetAttributeArgs
startswithr;   pluralappendrK   rG   rI   rR   r   r   GetDestFromParamhasattrGetFlagFromDestr   ArgumentformatrT   r'   rQ   )r   	namespacerF   rS   rH   specinfoargr;   	parameterr[   flags               r   GenerateArgs&AddCompleterResourceFlags.GenerateArgsh   s   D#@@FB ##!)">"> 9$79d**D62::499Ed&&(#88t$$#(#**Z
 +/;;C#**W
C ) #F$&..22/%%	
 D ""''22)!229>>B9##
!11$7mm)+22  **33Y^^E	F 	C 3 mm.0DO 	KK Kr   c                     U R                   R                  X R                  5      nU R                   R                  X5      $ r   )rR   r    rQ   r%   )r   r#   r   r;   r$   s        r   Completions%AddCompleterResourceFlags.Completions   s6    %%33__&N$$V<<r   )
__argument__completer)
r'   r(   r)   r*   r+   r   rq   rt   r,   __classcell__)rT   s   @r   rM   rM   `   s    <
,\= =r   rM   c                   .    \ rS rSrSr\S 5       rS rSrg)Run   aA  Cloud SDK completer module tester.

*{command}* is an ideal way to debug completer modules without interference
from the shell.  Shells typically ignore completer errors by disabling all
standard output, standard error and exception messaging.  Specify
`--verbosity=INFO` to enable completion and resource cache tracing.
c                    [         R                  " / 5      R                  U 5        U R                  SSS9  U R                  SSS9  U R                  S[        R
                  " [        [        [        [        [        S.S9S	S
9  [        R                  " U 5        U R                  SS[        R                  " 5       SS9  U R                  SS[        R
                  " 5       SS9  U R                  SSSSS9  U R                  S[        SS9  g )Nz--resource-spec-pathzHThe resource spec path for a resource argument auto-generated completer.)r]   z--attributezTThe name of the resource attribute for a resource argument auto-generated completer.z--resource-presentation-kwargs)r4   r.   rd   r3   rW   )rl   a-  Dict of kwargs to be passed to the presentation spec for the resource argument for which a completer is being tested, such as name, prefixes, plural, flag name overrides (format as a list of semicolon-separated key:value pairs). Prefixes is False by default. Name is the resource spec name by default.)rD   r]   z	--qualifyNAMEzA list of resource parameter names that must always be qualified. This is a manual setting for testing. The CLI sets this automatically.)metavarrD   r]   z--kwargsz
NAME=VALUEzKeyword arg dict passed to the completer constructor. For example, use this to set the resource collection and list command for `DeprecatedListCommandCompleter`:

  --kwargs=collection=...,foo="..."z--stack-trace
store_trueTzGEnable all exception stack traces, including Cloud SDK core exceptions.)actiondefaultr]   rF   a  The completer module path. Run $ gcloud meta completers list` to list the module paths of the available completers. A completer module may declare additional flags. Specify `--help` after _MODULE_PATH_ for details on the module specific flags.

NOTE: To test resource argument completers, use the module path "googlecloudsdk.command_lib.util.completers:CompleterForAttribute". The flags `--resource-spec-path`, `--attribute`, and (if desired) `--resource-presentation-kwargs` must be provided BEFORE the positional. Unlike with most gcloud commands, the arguments are generated on the fly using the completer you provide, so all the information to create a resource completer needs to be provided up-front. For example:

  $ {command} --resource-spec-path MODULE_PATH:SPEC_OBJECT --attribute ATTRIBUTE_NAME --resource-presentation-kwargs flag_name_overrides=ATTRIBUTE1:FLAG1;ATTRIBUTE2:FLAG2 googlecloudsdk.command_lib.util.completers:CompleterForAttribute)r   r]   )r   r`   AddToParseradd_argumentr   ArgDictstrboolr   AddCacheFlagArgListAddDynamicPositionalrM   )parsers    r   ArgsRun.Args   s@    !!"%11&9
   *  , (  '*  "#G  I F#
  "$	  &   "4	  6 	   (Q   r   c           
        ^ UR                   =(       d    0 n[        R                  " UR                  SS9 n[        R
                  " SR                  UR                  5      5        UR                  (       d  0 Ul        UR                  (       ac  [        UR                  40 UD6nSUl        [        R                  " U/5      R                  UR                  5      mU4S jnXQR                  l        [#        UR$                  4X1R&                  UR                  UUR(                  S.UR                  D6nUR+                  XR-                  S5      5      nUR.                  b(  UR1                  UR.                  U5      nU/sSSS5        $  [2        R4                  " S	5      n	U	c  O5 UR1                  X5      n
U
(       a  [G        S
RI                  U
5      5        MO  [J        RL                  RO                  S
5         SSS5        g! [6        [8        4 af  nUR:                  (       a   [<        R>                  " [7        U5      5        O*[        R@                  " [B        RD                  " U5      5         SnAM  SnAff = f! , (       d  f       g= f)z'Returns the results for one completion.T)createzcache name {}Fc                     > A AT$ r   r   )rS   r;   resource_infos     r   ResourceInfoMonkeyPatch(Run.Run.<locals>.ResourceInfoMonkeyPatch   s    F
r   )r@   rG   r<   rH   rI   r^   Nz
COMPLETE> 
)(r_   r   GetCacher@   r   rm   rj   r4   r;   r:   r>   rW   r   r`   ra   CONCEPTSArgNameToConceptInforK   rF   rG   rI   r    GetPositionalArgumentr^   r%   r   PromptResponse	Exception
SystemExitstack_tracer
   reraiseerrorsix	text_typeprintjoinsysstderrwrite)r   rS   rH   r@   rl   r   r   r$   matchesr4   completionser   s               @r   rz   Run.Run   s
   ;;Ar			TZZ	5	hh%%ejj12[[ 
	 	 ####!# '55tf=EEdiiP	 .E*


"'//1NN	
 KKi !..
**+ABDn		"	"	.$$T%>%>Oy= 
6	5> ((6<
	!**4@+ 
		+&
'  
jjt] 
6	5J :& 	y|,IIcmmA&'
	K 
6	5s>   E
I<
I<&H7AI<I9AI4.I<4I99I<<
J
r   N)	r'   r(   r)   r*   r+   staticmethodr   rz   r,   r   r   r   rz   rz      s#     B BH1r   rz   )NNNNN)r+   r   googlecloudsdk.callioper   r   r   googlecloudsdk.command_lib.metar   googlecloudsdk.command_lib.utilr   (googlecloudsdk.command_lib.util.conceptsr   r	   googlecloudsdk.corer
   r   r   googlecloudsdk.core.consoler   r   objectr   r>   rK   DynamicPositionalActionrM   Commandrz   r   r   r   <module>r      sw     -  / ( 5 6 > D G * # + 2 
? ?( 48JN+29= 1 I I 9=x$,, r   