U f @sddlZddlZddlZddlZddlmZddlmZddlm Z m Z m Z m Z m Z z ddlZWn*ek rejdedYnXddlmZmZmZddlmZd d Zeejd d eejd dddejdddedddgddejdddejddejedej ej!e e e ddddZ"eej#e e e$dd d!Z%e"&ej ejd"d#ed#d$d%d&gd'dej!e'dd(d)d*Z(e"&ej ej)d+d d,ej)d-d d,ej!e e dd.d/d0Z*e"&ej ej)d+d d,ej!e dd1d2d3Z+e"&ej ej)d+d d,ej!e dd1d4d5Z,e"j&d6d id7ej ejd8d d9d:ej)d;dd?d@Z.e e$e e$e$fe/dAdBdCZ0dS)DN)contextmanager)Popen)AnyDictIOIteratorListzkIt seems python-dotenv is not installed with cli option. Run pip install "python-dotenv[cli]" to fix this.) dotenv_valuesset_key unset_key) __version__cCs6z t}Wntk r"YdSXtj|d}|S)zZ Return a path for the ${pwd}/.env file. If pwd does not exist, return None. Nz.env)osgetcwdFileNotFoundErrorpathjoin)cwdrr;/opt/alt/python38/lib/python3.8/site-packages/dotenv/cli.py enumerate_envs  rz-fz--fileT)Z file_okayzNLocation of the .env file, defaults to .env file in current working directory.)defaulttypehelpz-qz--quotealwaysneverautozbWhether 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)ctxfilequoteexportreturncCs|||d|_dS)zAThis script is used to set, get or unset values from a .env file.)QUOTEEXPORTFILEN)obj)rrr r!rrrcli"sr')rr"c csbzt| }|VW5QRXWn>tk r\}z td|tjdtdW5d}~XYnXdS)z~ Open a file and yield the corresponding (decoded) stream. Exits with error code 2 if the file cannot be opened. zError opening env file: )rN)openOSErrorprintsysstderrexit)rstreamexcrrr stream_file3s  r1z--formatsimplejsonshellr!zlThe format in which to display the list. Default format is simple, which displays name=value without quotes.)rformatr"c Cs|jd}t|}t|d}W5QRX|dkrHttj|dddnX|dkrTdnd }t|D]>}||}|d k r`|d krt |}t||d |q`d S) z!Display all the stored key/value.r%r/r3r(T)indent sort_keysr!zexport N)r!r4=) r&r1r clickechor3dumpssortedshlexr )rr5rr/valuesprefixkvrrrlistCs    rDkey)requiredvalue)rrErGr"cCsZ|jd}|jd}|jd}t|||||\}}}|rNt|d|ntddS)zStore the given key/value.r%r#r$r:r N)r&r r;r<r.)rrErGrr r!successrrrset\s   rI)rrEr"c CsN|jd}t|}t|d}W5QRX||}|rBt|ntddS)z%Retrieve the value for the given key.r%r6r N)r&r1r getr;r<r.)rrErr/r@Z stored_valuerrrrJls    rJcCsF|jd}|jd}t|||\}}|r:td|ntddS)zRemoves the given key.r%r#zSuccessfully removed r N)r&r r;r<r.)rrErr rHrrrunset}s   rKZignore_unknown_options)Zcontext_settingsz--override/--no-overridezKOverride variables from the environment file with those from the .env file.)rr commandline)nargsr)roverriderLr"csr|jd}tj|s,tjd|d|dfddt|D}|s\tdt dt ||}t |d S) z/Run command with environment variables present.r%zInvalid value for '-f' "z" does not exist.)rcs,i|]$\}}|dk rs"|tjkr||qS)N)renviron).0rBrCrOrr s  zrun..zNo command given.r N) r&rrisfiler;Z BadParameterr itemsr<r. run_command)rrOrLrZdotenv_as_dictretrrRrruns       rX)commandenvr"cCs8tj}||t|ddd|d}|\}}|jS)awRun 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 TrF)universal_newlinesbufsizer4rZ)rrPcopyupdater communicate returncode)rYrZZcmd_envp_rrrrVs   rV)1r3rr?r, contextlibr subprocessrtypingrrrrrr; ImportErrorr-writer.mainr r r rr rgroupoptionPathZChoiceZBOOLZversion_optionZ pass_contextContextr'PathLikestrr1rYboolrDargumentrIrJrKZ UNPROCESSEDrXintrVrrrrs|          $      "