o
    +'h  ã                   @   sÎ  d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZm	Z	m
Z
mZmZ zd dlZW n ey@   ej d¡ e d¡ Y nw ddlmZmZmZ ddlmZ dee fd	d
„Ze ¡ ejddeƒ ejdd�dd�ejddde g d¢¡dd�ejdddejdd�ejed�ej dej!dedededdf
dd „ƒƒƒƒƒƒZ"ed!ej#de
e	e  fd"d#„ƒZ$e" %¡ ej ejd$d%e g d&¢¡d'd�dej!d(e&ddfd)d*„ƒƒƒZ'e" %¡ ej ej(d+dd,�ej(d-dd,�dej!d+ed-eddfd.d/„ƒƒƒƒZ)e" %¡ ej ej(d+dd,�dej!d+eddfd0d1„ƒƒƒZ*e" %¡ ej ej(d+dd,�dej!d+eddfd2d3„ƒƒƒZ+e"j%d4did5�ej ejd6dd7d8�ej(d9d:ej,d;�dej!d<e&d9ee ddfd=d>„ƒƒƒƒZ-d?ee d@eeef ddfdAdB„Z.dS )Cé    N)Úcontextmanager)ÚAnyÚDictÚIOÚIteratorÚListÚOptionalzkIt seems python-dotenv is not installed with cli option. 
Run pip install "python-dotenv[cli]" to fix this.é   )Údotenv_valuesÚset_keyÚ	unset_key)Ú__version__Úreturnc                  C   s4   zt  ¡ } W n
 ty   Y dS w t j | d¡}|S )zZ
    Return a path for the ${pwd}/.env file.

    If pwd does not exist, return None.
    Nz.env)ÚosÚgetcwdÚFileNotFoundErrorÚpathÚjoin)Úcwdr   © r   ú@C:\Users\shubh\Videos\agent\nova\Lib\site-packages\dotenv/cli.pyÚenumerate_env   s   ÿr   z-fz--fileT)Z	file_okayzNLocation of the .env file, defaults to .env file in current working directory.)ÚdefaultÚtypeÚhelpz-qz--quoteÚalways)r   ÚneverÚautozbWhether to quote or not the variable values. Default mode is always. This does not affect parsing.z-ez--exportFz;Whether to write the dot file as an executable bash script.)ÚversionÚctxÚfileÚquoteÚexportc                 C   s   |||dœ| _ dS )zAThis script is used to set, get or unset values from a .env file.)ÚQUOTEÚEXPORTÚFILEN)Úobj)r   r    r!   r"   r   r   r   Úcli!   s   r'   r   c              
   c   s~   � zt | ƒ�}|V  W d  ƒ W dS 1 sw   Y  W dS  ty> } ztd|› �tjd� tdƒ W Y d}~dS d}~ww )z~
    Open a file and yield the corresponding (decoded) stream.

    Exits with error code 2 if the file cannot be opened.
    NzError opening env file: )r    é   )ÚopenÚOSErrorÚprintÚsysÚstderrÚexit)r   ÚstreamÚexcr   r   r   Ústream_file2   s   €
&ÿ€þr1   z--formatÚsimple)r2   ÚjsonÚshellr"   zlThe format in which to display the list. Default format is simple, which displays name=value without quotes.Úformatc                 C   sº   | j d }t|ƒ�}t|d�}W d  ƒ n1 sw   Y  |dkr/t tj|ddd�¡ dS |dkr5d	nd
}t|ƒD ]}|| }|durZ|dv rNt 	|¡}t |› |› d|› �¡ q;dS )z!Display all the stored key/value.r%   ©r/   Nr3   r(   T)ÚindentÚ	sort_keysr"   zexport Ú )r"   r4   ú=)
r&   r1   r
   ÚclickÚechor3   ÚdumpsÚsortedÚshlexr!   )r   r5   r    r/   ÚvaluesÚprefixÚkÚvr   r   r   ÚlistB   s   

ÿ
€ûrD   Úkey)ÚrequiredÚvaluec                 C   s\   | j d }| j d }| j d }t|||||ƒ\}}}|r(t |› d|› �¡ dS tdƒ dS )zStore the given key/value.r%   r#   r$   r:   r	   N)r&   r   r;   r<   r.   )r   rE   rG   r    r!   r"   Úsuccessr   r   r   Úset[   s   


rI   c                 C   sd   | j d }t|ƒ�}t|d�}W d  ƒ n1 sw   Y  | |¡}|r,t |¡ dS tdƒ dS )z%Retrieve the value for the given key.r%   r6   Nr	   )r&   r1   r
   Úgetr;   r<   r.   )r   rE   r    r/   r@   Zstored_valuer   r   r   rJ   k   s   

ÿ
rJ   c                 C   sH   | j d }| j d }t|||ƒ\}}|rt d|› �¡ dS tdƒ dS )zRemoves the given key.r%   r#   zSuccessfully removed r	   N)r&   r   r;   r<   r.   )r   rE   r    r!   rH   r   r   r   Úunset|   s   

rK   Zignore_unknown_options)Zcontext_settingsz--override/--no-overridezKOverride variables from the environment file with those from the .env file.)r   r   Úcommandlineéÿÿÿÿ)Únargsr   Úoverridec                    sj   | j d }tj |¡stjd|› d�| d�‚‡ fdd„t|ƒ ¡ D ƒ}|s.t d¡ t	dƒ t
||ƒ d	S )
z/Run command with environment variables present.r%   zInvalid value for '-f' "z" does not exist.)r   c                    s,   i | ]\}}|d urˆ s|t jvr||“qS )N)r   Úenviron)Ú.0rB   rC   ©rO   r   r   Ú
<dictcomp>š   s
    þzrun.<locals>.<dictcomp>zNo command given.r	   N)r&   r   r   Úisfiler;   ZBadParameterr
   Úitemsr<   r.   Úrun_command)r   rO   rL   r    Zdotenv_as_dictr   rR   r   ÚrunŠ   s   


þ

þ
rW   ÚcommandÚenvc                 C   s,   t j ¡ }| |¡ t j| d | |d� dS )aå  Replace the current process with the specified command.

    Replaces the current process with the specified command and the variables from `env`
    added in the current environment variables.

    Parameters
    ----------
    command: List[str]
        The command and it's parameters
    env: Dict
        The additional environment variables

    Returns
    -------
    None
        This function does not return any value. It replaces the current process with the new one.

    r   )ÚargsrY   N)r   rP   ÚcopyÚupdateÚexecvpe)rX   rY   Zcmd_envr   r   r   rV   ¦   s   

rV   )/r3   r   r?   r,   Ú
contextlibr   Útypingr   r   r   r   r   r   r;   ÚImportErrorr-   Úwriter.   Úmainr
   r   r   r   r   Ústrr   ÚgroupÚoptionÚPathZChoiceÚBOOLZversion_optionZpass_contextÚContextr'   ÚPathLiker1   rX   ÚboolrD   ZargumentrI   rJ   rK   ZUNPROCESSEDrW   rV   r   r   r   r   Ú<module>   s~     ý
þ
þ
þ
,þ$ý(&