o
    ;i@                  	   @   sb  d dl mZmZmZ d dlZd dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZmZ d dlmZ d	Zejd
eddZG dd deZejdddd+dee fddZdZejdeddeeejddf fddZdZejdedejddfedded efd!dZd"Zejd#edej dd$d%ej dd&d%fd'ed(ee d)ee fd*d#Z!dS ),    )	AnnotatedOptionalUnionN)
UsageError)Text)environments)check_environment_name)
YES_OPTIONdisplay_table)configa  Create and interact with Environments

Environments are sub-divisons of workspaces, allowing you to deploy the same app
in different namespaces. Each environment has their own set of Secrets and any
lookups performed from an app in an environment will by default look for entities
in the same environment.

Typical use cases for environments include having one for development and one for
production, to prevent overwriting production apps when developing new features
while still being able to deploy changes to a live environment.
environmentT)namehelpno_args_is_helpc                   @   s"   e Zd ZdefddZdd ZdS )RenderableBoolvaluec                 C   s
   || _ d S N)r   )selfr    r   I/home/ubuntu/.local/lib/python3.10/site-packages/modal/cli/environment.py__init__      
zRenderableBool.__init__c                 C   s
   t | jS r   )reprr   )r   r   r   r   __rich__    r   zRenderableBool.__rich__N)__name__
__module____qualname__boolr   r   r   r   r   r   r      s    r   listz.List all environments in the current workspace)r   r   Fjsonc           	      C   s   t  }td}|D ]}|jdu r|d u r|j}qg }|D ]}|j|k}| r+t|nt|}|j|j|g}|	| qt
g d|| d d S )Nr   T)r   z
web suffixactive)r   )r   list_environmentsr   getdefaultr   strr   webhook_suffixappendr
   )	r   envs
active_envenv
table_dataitem	is_activeis_active_displayrowr   r   r   list_$   s   

r/   z1Create a new environment in the current workspacecreater   z;Name of the new environment. Must be unique. Case sensitive)r   c                 C   s&   t |  t|  td|   d S )NzEnvironment created: )r   r   create_environmenttyperecho)r   r   r   r   r0   ;   s   
zDelete an environment in the current workspace

Deletes all apps in the selected environment and deletes the environment irrevocably.
deletez5Name of the environment to be deleted. Case sensitive)yesr5   c                C   s:   |st jd|  dddd t|  t d|   d S )Nz=Are you sure you want to irrevocably delete the environment 'zB' and all its associated Apps, Secrets, Volumes, Dicts and Queues?FT)r#   abortzEnvironment deleted: )r2   confirmr   delete_environmentr3   )r   r5   r   r   r   r4   H   s   

	z/Update the name or web suffix of an environmentupdatezNew name of the environment)r#   r   z9New web suffix of environment (empty string is no suffix)current_nameset_nameset_web_suffixc                 C   sB   |d u r|d u rt d|rt| tj| ||d td d S )NzLYou need to at least one new property (using --set-name or --set-web-suffix))new_namenew_web_suffixzEnvironment updated)r   r   r   update_environmentr2   r3   )r:   r;   r<   r   r   r   r9   _   s   )F)"typingr   r   r   r2   clickr   	rich.textr   modalr   modal._utils.name_utilsr   modal.cli.utilsr	   r
   modal.configr   ENVIRONMENT_HELP_TEXTTyperenvironment_clir   commandr   r/   ENVIRONMENT_CREATE_HELPr$   Argumentr0   ENVIRONMENT_DELETE_HELPr4   ENVIRONMENT_UPDATE_HELPOptionr9   r   r   r   r   <module>   sN    
