Skip to content

Commit

Permalink
canonicalize QSV_DOTENV_PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
jqnatividad committed Jan 25, 2024
1 parent 73c8acf commit c0e5c97
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/ENVIRONMENT_VARIABLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br>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`. |
Expand Down
8 changes: 5 additions & 3 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
}

Expand Down

0 comments on commit c0e5c97

Please sign in to comment.