
    [                         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Jr  SSKJr  \R,                   " S S\R.                  5      5       rg)z&Command to delete named configuration.    )absolute_import)division)unicode_literals)base)
completers)config)log)
properties)named_configs)properties_file)
console_io)resource_printer)universe_descriptorc                   n    \ rS rSrSrSSS.r\S 5       rS\S\	4S	 jr
S\SS
4S jrS\S\4S jrS rSrg
)Delete"   zDeletes a named configuration.an            {description} You cannot delete a configuration that is active, even
          when overridden with the --configuration flag.  To delete the current
          active configuration, first `gcloud config configurations activate`
          another one.

          See `gcloud topic configurations` for an overview of named
          configurations.
          a;            To delete an existing configuration named `my-config`, run:

            $ {command} my-config

          To delete more than one configuration, run:

            $ {command} my-config1 my-config2

          To list existing configurations, run:

            $ gcloud config configurations list
          )DESCRIPTIONEXAMPLESc                 D    U R                  SS[        R                  SS9  g)zAdds args for this command.configuration_names+zNName of the configuration to delete. Cannot be currently active configuration.)nargs	completerhelpN)add_argumentr   NamedConfigCompleter)parsers    +lib/surface/config/configurations/delete.pyArgsDelete.Args?   s+     118      universe_domainreturnc                 6   [         R                  R                  5       n[        UR	                  5       5       H^  u  p4[
        R                  R                  SS[        R                  " UR                  /5      SS9nUS   R                  S5      U:X  d  M^    g   g)zDetermines whether the universe domain is set in any other config.

Args:
  universe_domain: The universe domain to check for in any other config.

Returns:
  True if the universe domain is set in any other config, False otherwise.
T
list_unsetinclude_hiddenr   only_file_contentscorer"   F)r   ConfigurationStore
AllConfigssorteditemsr
   VALUES	AllValuesr   PropertiesFile	file_pathget)selfr"   all_configs_user_configpropss         r   _UniverseDomainSetInAnyConfig$Delete._UniverseDomainSetInAnyConfigL   s      22==?K !2!2!45)))88$$% " * e 
v		,	-	@ 6 r!   Nc                 ~    [         R                  " 5       nU R                  U5      (       d  UR                  U5        gg)zDeletes the universe descriptor if it is not used in any other config.

Args:
  universe_domain: The universe domain of the descriptor to delete.
N)r   UniverseDescriptorr8   "DeleteDescriptorFromUniverseDomain)r3   r"   universe_descriptor_objs      r   _DeleteUniverseDescriptor Delete._DeleteUniverseDescriptorc   s:     2DDF--o>>@@
 ?r!   config_namec                    [         R                  R                  5       n[        UR	                  5       5       H  u  p4UR
                  U:X  d  M  [        R                  R                  SS[        R                  " UR                  /5      SS9nUS   R                  S5      =(       d.    [        R                  R                  R                  R                  s  $    [        R                  R                  R                  R                  $ )zReturns the universe domain of the given configuration.

Args:
  config_name: The name of the configuration to get the universe domain of.

Returns:
  The universe domain of the given configuration or the default if not
  found.
Tr%   r)   r"   )r   r*   r+   r,   r-   namer
   r.   r/   r   r0   r1   r2   r)   r"   default)r3   r@   all_named_configsr5   r6   r7   s         r   _GetConfigurationUniverseDomain&Delete._GetConfigurationUniverseDomaino   s     &88CCE !2!8!8!:;			[	(!!+++::&&'  $ , 
 &M/0 >  %%55==	
 < !!11999r!   c                    [         R                  R                  5       nUR                  UR                  ;   a/  [         R
                  " SR                  UR                  5      5      eSn[        R                  " UR                  U[        R                  S9  [        R                  " SSS9  UR                   H  nU R                  U5      n[         R                  R                  U5        [        R                   " U5      nUR                  5          U R#                  U5        [        R*                  " U5        M     g ! [$        R&                   a"  n[        R(                  " SUU5         S nANLS nAff = f)NzDeleting named configuration failed because configuration [{0}] is set as active.  Use `gcloud config configurations activate` to change the active configuration.z;list[title="The following configurations will be deleted:"])outT)rC   cancel_on_noz?Failed to delete universe descriptor for universe domain %s: %s)r   r*   ActiveConfigrB   r   NamedConfigErrorformatr   Printr	   statusr   PromptContinuerE   DeleteConfigr   GetConfigStorer>   r   UniverseDescriptorErrorwarningDeletedResource)r3   argsactive_configfmtconfiguration_namedelete_config_universe_domainconfig_store_to_deletees           r   Run
Delete.Run   s<    "44AACMT555**::@&  ;  HC433ScjjId>"66&*&J&J
'# &&334FG%445GH))+
&&'DE 
,- 7 !88 
M)	
 	

s   D??E5E00E5 )__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr   strboolr8   r>   rE   r\   __static_attributes__r^   r!   r   r   r   "   sh    &-2 
 
3 4 .
s 
t 
: : :6 .r!   r   N)rc   
__future__r   r   r   googlecloudsdk.callioper   !googlecloudsdk.command_lib.configr   googlecloudsdk.corer   r	   r
   "googlecloudsdk.core.configurationsr   r   googlecloudsdk.core.consoler   googlecloudsdk.core.resourcer   'googlecloudsdk.core.universe_descriptorr   UniverseCompatibleSilentCommandr   r^   r!   r   <module>rs      s[     - &  ' ( 8 & # * < > 2 9 G G.T G. G.r!   