a
   |n_                
   @   s  d dl Z d dlZd dlmZ zd dlZW n( eyP   ejd ed Y n0 ddl	m
Z
mZ ddlmZmZmZmZ ddlmZ e
rd dlmZmZ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 dd Z!e!" ej dd Z#e!" ej ej$dddej$d ddd!d" Z%e!" ej ej$dddd#d$ Z&e!" ej ej$dddd%d& Z'e!j"d'did(ej ej$d)d*ej(d+d,d- Z)d.d/ Z*e+d0kre!  dS )1    N)PopenzkIt seems python-dotenv is not installed with cli option. 
Run pip install "python-dotenv[cli]" to fix this.   )IS_TYPE_CHECKINGto_env)dotenv_valuesget_keyset_key	unset_key)__version__)AnyListDictz-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.)versionc                 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)ctxfilequoteexport r   ./usr/lib/python3.9/site-packages/dotenv/cli.pycli   s    

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valuec                 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.   r0   r   r   r   successr   r   r   set9   s    


r3   c                 C   sV   | j d }tj|s(tjd| | dt||}|rJtd||f  ntd dS )z%Retrieve the value for the given key.r   r    r!   r"   r   N)	r   r#   r$   r%   r&   r'   r   r)   r1   )r   r.   r   Zstored_valuer   r   r   getJ   s    

r4   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)   r1   )r   r.   r   r   r2   r   r   r   unset]   s    

r5   Zignore_unknown_options)Zcontext_settingscommandline)nargsr   c                 C   sj   | j d }tj|s(tjd| | ddd t| D }|sTt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   s&   i | ]\}}|d urt |t |qS )N)r   ).0r+   r,   r   r   r   
<dictcomp>x       zrun.<locals>.<dictcomp>zNo command given.r   N)r   r#   r$   r%   r&   r'   r   r(   r)   r1   run_command)r   r6   r   r*   retr   r   r   runl   s    


r>   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)Zuniversal_newlinesbufsizeshellenv)r#   environcopyupdater   Zcommunicate
returncode)commandrA   Zcmd_envp_r   r   r   r<      s    

r<   __main__),r#   sys
subprocessr   r&   ImportErrorstderrwriter1   compatr   r   mainr   r   r   r	   r   r
   typingr   r   r   groupoptionr$   joingetcwdPathZChoiceZBOOLZversion_optionZpass_contextr   rF   r-   argumentr3   r4   r5   ZUNPROCESSEDr>   r<   __name__r   r   r   r   <module>   sf   



	#
