
                         f    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 r
S	 rSS jrg
)z)Helper methods for interactive prompting.    )absolute_import)division)unicode_literals)errors)resource_args)
console_ioc                   ^
 / n U" 5       n[        R                  U    nU(       a=  SUR                  -  n[
        R                  " X5/-   SU-  S9nU[        U5      :  a  X6   $ [        R                  " U 5      m
U
4S jnSUR                  -   nSU-  n	[
        R                  " XxU	5      $ ! [         R                   a     Nf = f)a  Prompts the user to select a resource.

Args:
  name: the name of the resource. For example, "environment" or "developer".
  long_name: a longer form of `name` which the user will see in prompts.
    Should explain the context in which the resource will be used. For
    example, "the environment to be updated".
  list_func: a function that returns the names of existing resources.

Returns:
  The resource's identifier if successful, or None if not.
z(some other %s)z
Select %s:)prompt_stringc                 *   > TR                  U 5      S L$ N)search)responsevalid_patterns    0lib/googlecloudsdk/command_lib/apigee/prompts.py<lambda>,ResourceFromFreeformPrompt.<locals>.<lambda>:   s    }33H=TI    z'Doesn't match the expected format of a z
Enter %s: )
r   RequestErrorr   ENTITIES	docs_namer   PromptChoicelenValidPatternForEntityPromptWithValidator)name	long_name	list_funcresource_listentity_namesenter_manuallychoice	validator	error_strprompt_messager   s             @r   ResourceFromFreeformPromptr%      s     -	KM
 ''-,&)?)??N$$(("Y.0F
 M""""55d;-I)7,:P:PP))+.		'	'	n	MM) 
		 		s   B* *C Cc                    / nSnU[        U5      ::  a  U[        U5      :  a  USU X4S-   S -   nO6U[        U5      :X  a'  [        R                  " U 5      nUR                  U5        U Vs/ s H  nSU-  PM
     nnUR                  U5        UR                  U(       a  SOU5        [        R                  " U5      nU[        U5      ::  a  M  U$ s  snf )a+  Returns a list of strings inputted by the user.

Args:
  message: the message to display when prompting for a new string.
  add_message: the menu option for adding a new string to the list.
  empty_done_message: the menu option to display for the "Done" option if no
    strings have been selected.
r   N   Remove `%s`Done)r   r   PromptResponseappendr   )messageadd_messageempty_done_messagechosenmenu_option
input_dataitemoptionss           r   ListFromFreeformPromptr4   A   s     &+s6{"S[ l{#f1_-=&>>f	F	#,,W5jmmJ067}t#G7NN;NNV6);<))'2K 	s6{" 
-	 8s   +CNc                 ,   U" 5       nU(       d:  [         R                  U    R                  n[        R                  " SU< SU< S3S9e/ nSn[        U5      S-   nU[        U5      :w  Ga  U[        U5      :  a  USU XWS-   S -   nO0U[        U5      :  a!  U[        U5      -
  nUR                  Xh   5        U V	s/ s H  oU;  d  M
  U	PM     nn	U V	s/ s H  n	SU	-  PM
     n
n	X V	s/ s H  n	SU	-  PM
     sn	-  n
U(       a&  S	S
R                  U5      -  nU
R                  S5        O4S[         R                  U    R                  -  nUb  U
R                  U5        [        R                  " XS9nU[        U5      :w  a  GM  U$ s  sn	f s  sn	f s  sn	f )a  Returns a list of resources selected by the user.

Args:
  name: the entity name for the resources being selected.
  list_func: a zero argument function that will return a list of existing
    resources.
  end_empty_message: text for the menu option that will return an empty list.
zCould not find any z$ to select. Check that at least one z4 has been created and is properly configued for use.)r,   Nr'   r(   zAdd `%s`zCurrently selected: %sz, r)   zNo %s selected yet)
r   r   r   r   EntityNotFoundErrorr   r+   joinr   r   )r   r   end_empty_messager   r   r/   	availabler0   indexr2   r3   r,   s               r   ResourceListFromPromptr;   Z   s    +-	&&t,66I

$
$ Y(* *
 &)M"Q&+s=))S[  l{#f1_-=&>>f	s=)	)CK'emmI$%"/F-$v3E-IF067}t#G7i8id
T!i88G(499V+<<gnnV$}'='=d'C'M'MMg		&()))'CK) 	s=))* 
- G78s   <	F	FF*Fr   )__doc__
__future__r   r   r   !googlecloudsdk.command_lib.apigeer   r   googlecloudsdk.core.consoler   r%   r4   r;    r   r   <module>rA      s-    0 &  ' 4 ; 2$NN2)r   