pub fn extract_env(
file_path: &Path,
) -> TreeResult<(BTreeMap<String, String>, Vec<PathBuf>)>Expand description
Extracts environment variables and the parent path from a specified file.
This function reads the given file_path to:
- Identify and extract environment variables specified using the
exportkeyword. - Identify any parent environment file via the special
# rsenv:comment. parent’s path can be relative to the child’s path.
The current working directory is temporarily changed to the directory of the file_path
during the extraction process to construct correct parent paths. It is restored
afterward.
§Arguments
file_path- A string slice representing the path to the .env file. The function will attempt to canonicalize this path.
§Returns
A Result containing:
- A tuple with:
- A
BTreeMapwith the key as the variable name and the value as its corresponding value. - An
Optioncontaining aUtf8PathBufpointing to the parent env file, if specified.
- A
- An error if there’s any problem reading the file, extracting the variables, or if the path is invalid.
§Errors
This function will return an error in the following situations:
- The provided
file_pathis invalid. - There’s an issue reading or processing the env file.
- The parent path specified in
# rsenv:is invalid or not specified properly.