microsoft / genaiscript

Automatable GenAI Scripting
https://microsoft.github.io/genaiscript/
MIT License
2.02k stars 116 forks source link

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

Closed pelikhan closed 2 weeks ago

pelikhan commented 2 weeks ago

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 https://github.com/microsoft/genaiscript/issues/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 ` 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](https://github.com/microsoft/genaiscript/actions/runs/11822343174)
github-actions[bot] commented 2 weeks ago

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