Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom .env file location via CLI/env #856

Merged
merged 4 commits into from
Nov 13, 2024
Merged

Support custom .env file location via CLI/env #856

merged 4 commits into from
Nov 13, 2024

Conversation

pelikhan
Copy link
Member

@pelikhan pelikhan commented Nov 13, 2024

Introduce the ability to specify a custom .env file location through a CLI argument or an environment variable. Update documentation to reflect these changes.

Fix for #837


  • 📁 Custom .env File Support: Introduced the ability to specify custom .env file locations in the documentation. Users can now define a custom path using the --env <file> CLI argument or by setting the GENAISCRIPT_ENV_FILE environment variable.

  • 🛠️ Error Logging Enhancement: Improved error logging by ensuring stack traces are only logged if both a stack is present and a nodeHost exists. This adds an additional check before printing verbose logs in non-quiet modes.

  • 🏗️ Configuration Flexibility: Enhanced the NodeHost class with more flexible .env file handling. It now checks for the existence of a .env file at a user-specified location, throwing an error if the file does not exist. If no custom path is provided, it defaults to resolving the standard .env filename.

generated by pr-describe

Copy link

The changes in the GIT_DIFF include:

  1. cli.ts:

    • An additional check for nodeHost is added before logging the stack trace in non-quiet mode. This ensures that the stack trace is logged only if nodeHost is available, which might be related to a contextual requirement in error handling.
  2. nodehost.ts:

    • The environment file path (dotEnvPath) now considers process.env.GENAISCRIPT_ENV_FILE as a user-provided path before falling back to a default.
    • A check for the existence of the .env file is added, throwing an error if the file is not found at the specified path. This change improves robustness by avoiding potential runtime errors due to a missing configuration file.

These changes improve error handling and configuration management within the CLI package.

LGTM 🚀

generated by pr-review

dotEnvPath = dotEnvPath || process.env.GENAISCRIPT_ENV_FILE
if (dotEnvPath) {
// if the user provided a path, check file existence
if (!(await exists(dotEnvPath)))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exists function is awaited, but it is not clear if it returns a Promise. Ensure that exists is an asynchronous function returning a Promise. If not, remove the await keyword. 🔍

generated by pr-review-commit async_await_misuse

dotEnvPath = dotEnvPath || process.env.GENAISCRIPT_ENV_FILE
if (dotEnvPath) {
// if the user provided a path, check file existence
if (!(await exists(dotEnvPath)))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exists function is used as if it returns a promise, but it's not clear if it is an async function. Ensure that exists is an async function or handle it appropriately.

generated by pr-review-commit async_function

@pelikhan pelikhan merged commit d0868d9 into main Nov 13, 2024
6 of 8 checks passed
@pelikhan pelikhan deleted the envconfig branch November 13, 2024 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant