From c0e5c9710390d84a7c4dffba00c2bb7a6f87dd37 Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Thu, 25 Jan 2024 09:24:40 -0500 Subject: [PATCH] canonicalize QSV_DOTENV_PATH --- docs/ENVIRONMENT_VARIABLES.md | 2 +- src/util.rs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/ENVIRONMENT_VARIABLES.md b/docs/ENVIRONMENT_VARIABLES.md index cf8c54f83..6da8580a8 100644 --- a/docs/ENVIRONMENT_VARIABLES.md +++ b/docs/ENVIRONMENT_VARIABLES.md @@ -2,7 +2,7 @@ | Variable | Description | | --- | --- | -| `QSV_DOTENV_PATH` | The filename of the dotenv file to load, OVERRIDING existing environment variables. This takes precedence over any other dotenv file in the filesystem. | +| `QSV_DOTENV_PATH` | The full pathname of the dotenv file to load, OVERRIDING existing environment variables. This takes precedence over any other dotenv files in the filesystem. | | `QSV_DEFAULT_DELIMITER` | single ascii character to use as delimiter. Overrides `--delimiter` option. Defaults to "," (comma) for CSV files & "\t" (tab) for TSV files when not set. Note that this will also set the delimiter for qsv's output to stdout.
However, using the `--output` option, regardless of this environment variable, will automatically change the delimiter used in the generated file based on the file extension - i.e. comma for `.csv`, tab for `.tsv` & `.tab` files. | | `QSV_SNIFF_DELIMITER` | if set, the delimiter is automatically detected. Overrides `QSV_DEFAULT_DELIMITER` & `--delimiter` option. Note that this does not work with stdin. | | `QSV_NO_HEADERS` | if set, the first row will **NOT** be interpreted as headers. Supersedes `QSV_TOGGLE_HEADERS`. | diff --git a/src/util.rs b/src/util.rs index 925dd6fbc..00d4d6ede 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1225,12 +1225,14 @@ pub fn load_dotenv() -> CliResult<()> { // whatever manually set environment variables are present. if let Ok(dotenv_path) = std::env::var("QSV_DOTENV_PATH") { - if let Err(e) = dotenvy::from_filename_override(dotenv_path.clone()) { + let canonical_dotenv_path = std::fs::canonicalize(dotenv_path)?; + if let Err(e) = dotenvy::from_filename_override(canonical_dotenv_path.clone()) { return fail_clierror!( - "Cannot process .env file set in QSV_DOTENV_PATH - {dotenv_path}: {e}" + "Cannot process .env file set in QSV_DOTENV_PATH - {}: {e}", + canonical_dotenv_path.display() ); } - log::info!("Using .env file: {dotenv_path}"); + log::info!("Using .env file: {}", canonical_dotenv_path.display()); return Ok(()); }