
    -                     J   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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\
R:                  5      r " S S\	R>                  5      r g)z&The meta cache completers run command.    )absolute_import)division)print_function)unicode_literalsN)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.Complete3   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)r2   r7   )r   ImportModulecallablepopsplitr   ResourcePresentationSpecr8   )resource_spec_pathkwargsresource_specr2   or7   s         r   _GetPresentationSpecrB   7   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!   )rB   r   r9   concept_spec
isinstancetyper   	TypeError)	module_pathrD   qualifyr@   presentation_kwargs	attributer?   presentation_specr   s	            r   _GetCompleterrO   K   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	$ )AddCompleterResourceFlagsd   z4Adds resource argument flags based on the completer.c                 J   > [         [        U ]
  " U0 UD6  S U l        S U l        g r   )superrQ   r   $_AddCompleterResourceFlags__argument%_AddCompleterResourceFlags__completer)r   argsr?   	__class__s      r   r   "AddCompleterResourceFlags.__init__g   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)rK   r@   rL   rM   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.)r^   ra   )resource_presentation_kwargsr>   rB   r   ConceptParserGetInfor8   GetAttributeArgs
startswithr?   pluralappendrO   rK   rM   rV   r   r   GetDestFromParamhasattrGetFlagFromDestr   ArgumentformatrX   r+   rU   )r   	namespacerJ   rW   rL   specinfoargr?   	parameterr_   flags               r   GenerateArgs&AddCompleterResourceFlags.GenerateArgsl   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   )rV   r$   rU   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   ru   rx   r0   __classcell__)rX   s   @r   rQ   rQ   d   s    <
,\= =r   rQ   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.)ra   z--attributezTThe name of the resource attribute for a resource argument auto-generated completer.z--resource-presentation-kwargs)r8   r2   rh   r7   r[   )rp   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.)rH   ra   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.)metavarrH   ra   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defaultra   rJ   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   ra   )r   rd   AddToParseradd_argumentr   ArgDictstrboolr
   AddCacheFlagArgListAddDynamicPositionalrQ   )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!   )rW   r?   resource_infos     r   ResourceInfoMonkeyPatch(Run.Run.<locals>.ResourceInfoMonkeyPatch   s    F
r   )rD   rK   r@   rL   rM   rb   Nz
COMPLETE> 
)(rc   r
   GetCacherD   r   rq   rn   r8   r?   r>   rB   r[   r   rd   re   CONCEPTSArgNameToConceptInforO   rJ   rK   rM   r$   GetPositionalArgumentrb   r)   r   PromptResponse	Exception
SystemExitstack_tracer   reraiseerrorsix	text_typeprintjoinsysstderrwrite)r   rW   rL   rD   rp   r   r   r(   matchesr8   completionser   s               @r   r~   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   r~   r0   r!   r   r   r~   r~      s#     B BH1r   r~   )NNNNN)!r/   
__future__r   r   r   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   rB   rO   DynamicPositionalActionrQ   Commandr~   r!   r   r   <module>r      s     - &  % ' 
 / ( 5 6 > D G * # + 2 
? ?( 48JN+29= 1 I I 9=x$,, r   