bacon icon indicating copy to clipboard operation
bacon copied to clipboard

feat: add an `env_file` configuration option to load environment variables from a file

Open xpepper opened this issue 5 months ago • 3 comments

Add env_file configuration option to load environment variables from a file

Note: Please note I'm still a beginner rustacean, so I appreciate feedback both on the code's idiomaticity and expressiveness.

This PR adds a new env_file configuration option that allows loading multiple environment variables from a file, providing an alternative to specifying them individually with the existing env option.

Features

  • File-based environment loading: Use env_file = "./.env" to load variables from a file
  • Standard .env format support: Supports KEY=VALUE format with comments and quoted values
  • Flexible configuration: Can be set globally or per-job
  • Proper priority handling: Direct env variables override env_file variables
  • Relative path resolution: Paths are resolved relative to the package directory
  • Graceful error handling: Missing files generate warnings but don't fail the build

Usage Examples

Global environment file:

# bacon.toml
env_file = "./.env"

xpepper avatar Jul 11 '25 22:07 xpepper

Can you please create an issue first so that we discuss whether we want this feature and its specification ?

Canop avatar Jul 12 '25 05:07 Canop

Can you please create an issue first so that we discuss whether we want this feature and its specification ?

Sure!

xpepper avatar Jul 12 '25 10:07 xpepper

Here's the proposal @Canop https://github.com/Canop/bacon/issues/376 🙏

xpepper avatar Jul 12 '25 10:07 xpepper