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

feat: dotenv support #2587

Merged
merged 1 commit into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ console = "0.15.0"
watchexec = "2.0.0"
atty = "0.2.14"
comfy-table = "5.0.0"
dotenv = "0.15.0"

# async / parallel
tokio = { version = "1", features = ["macros"] }
Expand Down
1 change: 1 addition & 0 deletions cli/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use std::{

#[tokio::main]
async fn main() -> eyre::Result<()> {
utils::load_dotenv();
handler::install()?;
utils::subscriber();
utils::enable_paint();
Expand Down
1 change: 1 addition & 0 deletions cli/src/forge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use opts::forge::{Opts, Subcommands};
use std::process::Command;

fn main() -> eyre::Result<()> {
utils::load_dotenv();
handler::install()?;
utils::subscriber();
utils::enable_paint();
Expand Down
11 changes: 11 additions & 0 deletions cli/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@ macro_rules! p_println {
}
pub(crate) use p_println;

/// Loads a dotenv file, ignoring potential failure.
///
/// We could use `tracing::warn!` here, but that would imply that the dotenv file can't configure
/// the logging behavior of Foundry.
Comment on lines +193 to +194
Copy link
Member Author

Choose a reason for hiding this comment

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

... because we would need to register the subscriber before loading .env

Copy link
Member

Choose a reason for hiding this comment

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

this will now auto load regardless which is a big change.

I think we should consider making this opt-in via Config?

Copy link
Member Author

Choose a reason for hiding this comment

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

not sure... if config is loaded, then dotenv won't take effect on config values? also, not sure why you would have a .env in your project w/o it being related. Not sure

Maybe it's possible to write a Figment provider? Although that would mean things outside the scope of config won't be interpreted (NO_COLOR etc)

///
/// Similarly, we could just use `eprintln!`, but colors are off limits otherwise dotenv is implied
/// to not be able to configure the colors. It would also mess up the JSON output.
pub fn load_dotenv() {
dotenv::dotenv().ok();
}

/// Disables terminal colours if either:
/// - Running windows and the terminal does not support colour codes.
/// - Colour has been disabled by some environment variable.
Expand Down