From 3320f040d76eae6183b6dbe5743321e442635bc3 Mon Sep 17 00:00:00 2001 From: Oliver Nordbjerg Date: Wed, 3 Aug 2022 15:56:53 +0200 Subject: [PATCH] feat: dotenv support --- Cargo.lock | 7 +++++++ cli/Cargo.toml | 1 + cli/src/cast.rs | 1 + cli/src/forge.rs | 1 + cli/src/utils.rs | 11 +++++++++++ 5 files changed, 21 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index b590080e63d7..c5ed4423e134 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1302,6 +1302,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + [[package]] name = "dunce" version = "1.0.2" @@ -1955,6 +1961,7 @@ dependencies = [ "color-eyre", "comfy-table 5.0.1", "console 0.15.0", + "dotenv", "dunce", "ethers", "eyre", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 33991aa6fde3..30418c31bc49 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -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"] } diff --git a/cli/src/cast.rs b/cli/src/cast.rs index 7fdd6c4e308f..60f0202cea51 100644 --- a/cli/src/cast.rs +++ b/cli/src/cast.rs @@ -44,6 +44,7 @@ use std::{ #[tokio::main] async fn main() -> eyre::Result<()> { + utils::load_dotenv(); handler::install()?; utils::subscriber(); utils::enable_paint(); diff --git a/cli/src/forge.rs b/cli/src/forge.rs index d4390d9343f7..bf8045426e03 100644 --- a/cli/src/forge.rs +++ b/cli/src/forge.rs @@ -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(); diff --git a/cli/src/utils.rs b/cli/src/utils.rs index 7b203206fb70..6bd237d8c6a8 100644 --- a/cli/src/utils.rs +++ b/cli/src/utils.rs @@ -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. +/// +/// 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.