
    V                         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
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r\" 5       rSrSS jrS rS rS rSS jrg)z8Contains utilities to support the `gcloud init` command.    )absolute_import)division)unicode_literals)projects_api)projects_util)
operations)
usage_text)util)log)	resources)
console_ioNzEnter a Project ID. Note that a Project ID CANNOT be changed later.
Project IDs must be 6-30 characters (lowercase ASCII, digits, or
hyphens) in length and start with a lowercase letter.    c                     [         R                  " U S9n[        U Vs/ s H  o"R                  PM     sn5      $ s  snf ! [         a5  n[
        R                  " S[        R                  " U5      5         SnAgSnAff = f)zReturns a list of project IDs the current user can list.

Args:
  limit: int, the maximum number of project ids to return.

Returns:
  list of str, project IDs, or None (if the command fails).
limitz%Listing available projects failed: %sN)	r   Listsorted	projectId	Exceptionr   warningsix	text_type)r   projectsprojecterrs       +lib/googlecloudsdk/command_lib/init_util.py_GetProjectIdsr   ,   sc      u-HH=H$$H=>>=	 KK7s9KLs%   A  ;A  A   
A?
+A::A?c                     [         R                  " U 5      n [        R                  " U5      n[        R
                  " U5      $ ! [         a     gf = f)NF)projects_command_utilParseProjectr   Getr   IsActiver   )
project_idproject_refr   s      r   _IsExistingProjectr%   =   sL    %22:>+{+G!!'**	  s   +A 
AAc                 :   U c  [         R                  " S5      =(       d    S$ U (       d!  [         R                  " SSS9(       d  g[        $ U(       aR  [         R                  " / SQSS9nUc  gUS	:X  a  [         R
                  " [        S
SSS9$ US:X  a  [        $ [        5       n [         R                  " U SS/-   SS[        R                  " 5       S9nUc  gU[        U 5      :X  a  [         R
                  " [        S
SSS9$ U[        U 5      S-   :X  a  [        $ X   $ )a  Prompt the user for a project ID, based on the list of available IDs.

Also allows an option to create a project.

Args:
  project_ids: list of str or None, the project IDs to prompt for. If this
    value is None, the listing was unsuccessful and we prompt the user
    free-form (and do not validate the input). If it's empty, we offer to
    create a project for the user.
  limit_exceeded: bool, whether or not the project list limit was reached. If
    this limit is reached, then user will be prompted with a choice to
    manually enter a project id, create a new project, or list all projects.

Returns:
  str, the project ID to use, or _CREATE_PROJECT_SENTINEL (if a project should
    be created), or None
Nz)Enter project ID you would like to use:  This account has no projects.zWould you like to create one?)prompt_string)Enter a project IDCreate a new projectzList projectszFThis account has a lot of projects! Listing them all can take a while.)messager   z+Project ID does not exist or is not active.T)allow_invalid   r)   r*   zPick cloud project to use: )r+   allow_freeformfreeform_suggester)r   PromptResponsePromptContinue_CREATE_PROJECT_SENTINELPromptChoicePromptWithValidatorr%   r   r	   TextChoiceSuggesterlen)project_idslimit_exceededidxs      r   _PromptForProjectIdr:   H   s6   $ $$35 =8<=$$'57 ##

!
!G!#C {	++

7
5	 
 
%%"$k)+ABB+#779		;#
 	[
c+))53	 
 c+""##		    c                    U(       a  X;   a  [        S5      e[        R                  R                  SU S9n [        R                  " U5      n [        R                  " U5      nU $ ! [
         aB  n[        R                  " SR                  [        R                  " U5      U S95         SnAgSnAff = f! [        R                   aB  n[        R                  " SR                  [        R                  " U5      U S95         SnAgSnAff = f)zBCreate a project and check that it isn't in the known project IDs.z3Attempting to create a project that already exists.zcloudresourcemanager.projects)r   zProject creation failed: {err}
Please make sure to create the project [{project}] using
    $ gcloud projects create {project}
or change to another project using
    $ gcloud config set project <PROJECT ID>)r   r   Nz8Project creation for project [{project}] failed:
  {err})
ValueErrorr   REGISTRYCreater   r   r   r   formatr   r   r   WaitForOperationOperationFailedException)r#   r7   r$   	create_opr   s        r   _CreateProjectrD      s    Z.
J
KK""))% * =+	##K0I++I6I 
! 
 KK ? @Fvc*J @F @@	A  
	,	, KKCJJc"J 	K 	89 	s/   A& B5 &
B208B--B25D	8DDc                    [        [        S-   S9nSnUb  [        U5      [        :  a  SnSnU (       a  U nO[        X5      nU[        La  UnU(       d  Ub  XA;   d
  Ub  U(       a  U$ O"U (       a  [        U 5      (       d	  U[        La  U$ U[        L a#  [        R                  " [        5      nU(       d  gOFU(       a"  SR                  USR                  U5      5      nOSn[        R                  " US	S
9(       d  g[        XA5      $ )zAllows user to select a project.

Args:
  preselected: str, use this value if not None

Returns:
  str, project_id or None if was not selected.
r-   r   FNTz)[{0}] is not one of your projects [{1}]. ,r'   zWould you like to create it?)r+   r(   )r   _PROJECT_LIST_LIMITr6   r:   r2   r%   r   r0   _ENTER_PROJECT_ID_MESSAGEr@   joinr1   rD   )preselectedr7   r8   selectedr#   r+   s         r   PickProjectrL      s    %81%<=+.[!14G!GN(J$[AJ11h	z8h ' 
+K8822++**+DEJ  ;BB
chh{+-g 0g$$'EG	
	00r;   )N)__doc__
__future__r   r   r   +googlecloudsdk.api_lib.cloudresourcemanagerr   r   'googlecloudsdk.api_lib.resource_managerr   googlecloudsdk.callioper	   #googlecloudsdk.command_lib.projectsr
   r   googlecloudsdk.corer   r   googlecloudsdk.core.consoler   r   rH   objectr2   rG   r   r%   r:   rD   rL    r;   r   <module>rW      sb     ? &  ' D E > . N # ) 2 
 
 "8   "<~801r;   