a
    ((a                     @   s^  d dl Z d dlZd dlmZ d dlmZmZmZ zd dlZW n( e	yd   ej
d ed Y n0 ddlmZmZmZmZ ddlmZ e ejdd	e je  d
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ejeeeddddZe  ejejddddZ!e  ejej"ddd ej"d!dd ejeedd"d#d$Z#e  ejej"ddd ejedd%d&d'Z$e  ejej"ddd ejedd%d(d)Z%ej d*did+ejejd,dd-d.ej"d/d0ej&d1eje'ee( dd2d3d4Z)ee( ee(e(f e*d5d6d7Z+e,d8krZe  dS )9    N)Popen)AnyDictListzkIt seems python-dotenv is not installed with cli option. 
Run pip install "python-dotenv[cli]" to fix this.   )dotenv_valuesget_keyset_key	unset_key)__version__z-fz--filez.envT)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exportreturnc                 C   s(   i | _ || j d< || j d< || j 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   Q/Users/bob/PycharmProjects/fastapi/venv/lib/python3.9/site-packages/dotenv/cli.pycli   s    

r   )r   r   c                 C   sX   | j d }tj|s(tjd| | dt|}| D ]\}}td||f  q8dS )z!Display all the stored key/value.r   Path "%s" does not exist.r   %s=%sN)	r   ospathisfileclickBadParameterr   itemsecho)r   r   dotenv_as_dictkvr   r   r   list%   s    
r,   key)requiredvalue)r   r-   r/   r   c                 C   sX   | j d }| j d }| j d }t|||||\}}}|rLtd||f  ntd dS )zStore the given key/value.r   r   r   r!   r   N)r   r	   r%   r(   exit)r   r-   r/   r   r   r   successr   r   r   set4   s    


r2   )r   r-   r   c                 C   sN   | j d }tj|s(tjd| | dt||}|rBt| ntd dS )z%Retrieve the value for the given key.r   r   r    r   N)	r   r"   r#   r$   r%   r&   r   r(   r0   )r   r-   r   Zstored_valuer   r   r   getD   s    

r3   c                 C   sD   | j d }| j d }t|||\}}|r8td|  ntd dS )zRemoves the given key.r   r   zSuccessfully removed %sr   N)r   r
   r%   r(   r0   )r   r-   r   r   r1   r   r   r   unsetV   s    

r4   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   )r   overrider5   r   c                    sn   | j d }tj|s(tjd| | d fddt| D }|sXtd t	d t
||}t	| dS )	z/Run command with environment variables present.r   z+Invalid value for '-f' "%s" does not exist.r    c                    s,   i | ]$\}}|d ur s"|t jvr||qS )N)r"   environ).0r*   r+   r8   r   r   
<dictcomp>t   s   zrun.<locals>.<dictcomp>zNo command given.r   N)r   r"   r#   r$   r%   r&   r   r'   r(   r0   run_command)r   r8   r5   r   r)   retr   r;   r   rund   s    





r?   )commandenvr   c                 C   s8   t j }|| t| ddd|d}| \}}|jS )aw  Run command in sub process.

    Runs the command in a sub process with 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
    -------
    int
        The return code of the command

    Tr   F)universal_newlinesbufsizeshellrA   )r"   r9   copyupdater   communicate
returncode)r@   rA   Zcmd_envp_r   r   r   r=      s    

r=   __main__)-r"   sys
subprocessr   typingr   r   r   r%   ImportErrorstderrwriter0   mainr   r   r	   r
   r   r   groupoptionr#   joingetcwdPathZChoiceZBOOLZversion_optionZpass_contextContextr   r@   r,   Zargumentr2   r3   r4   ZUNPROCESSEDboolstrr?   intr=   __name__r   r   r   r   <module>   sl   



$""
