From 38119966415a2b9b02c4adb8cbb6b9ad4e3b9a89 Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Wed, 15 Jan 2025 16:06:55 +0100 Subject: [PATCH] provide way for users to mute the warning by setting a FOUNDRY_DISABLE_NIGHTLY_WARNING environment variable --- crates/cli/src/opts/global.rs | 7 +++++-- crates/common/src/version.rs | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/cli/src/opts/global.rs b/crates/cli/src/opts/global.rs index 3f46e1ebfdcc..734c6960bd52 100644 --- a/crates/cli/src/opts/global.rs +++ b/crates/cli/src/opts/global.rs @@ -1,7 +1,7 @@ use clap::{ArgAction, Parser}; use foundry_common::{ shell::{ColorChoice, OutputFormat, OutputMode, Shell, Verbosity}, - version::NIGHTLY_VERSION_WARNING_MESSAGE, + version::{NIGHTLY_VERSION_WARNING_MESSAGE}, }; use serde::{Deserialize, Serialize}; @@ -51,7 +51,10 @@ impl GlobalArgs { } // Display a warning message if the current version is not stable. - if !self.json && env!("FOUNDRY_IS_NIGHTLY_VERSION") == "true" { + if std::env::var("FOUNDRY_DISABLE_NIGHTLY_WARNING").is_err() && + !self.json && + env!("FOUNDRY_IS_NIGHTLY_VERSION") == "true" + { let _ = sh_warn!("{}", NIGHTLY_VERSION_WARNING_MESSAGE); } diff --git a/crates/common/src/version.rs b/crates/common/src/version.rs index 109c4df27eab..147efa3416a0 100644 --- a/crates/common/src/version.rs +++ b/crates/common/src/version.rs @@ -1,7 +1,9 @@ use std::{env, error::Error}; pub const NIGHTLY_VERSION_WARNING_MESSAGE: &str = - "This is a nightly build of Foundry. It is recommended to use the latest stable version. See: https://book.getfoundry.sh/announcements"; + "This is a nightly build of Foundry. It is recommended to use the latest stable version. \ + Visit https://book.getfoundry.sh/announcements for more information. \n\ + To mute this warning set `FOUNDRY_DISABLE_NIGHTLY_WARNING` in your environment. \n"; #[allow(clippy::disallowed_macros)] /// Set the build version information for Foundry binaries. @@ -13,9 +15,7 @@ pub fn set_build_version() -> Result<(), Box> { // if on a tag: 0.3.0-stable+ba03de0019 let tag_name = option_env!("TAG_NAME"); let (is_nightly, version_suffix) = match tag_name { - Some(tag_name) if tag_name.eq_ignore_ascii_case("nightly") => { - (true, "-nightly".to_string()) - } + Some(tag_name) if tag_name.eq("nightly") => (true, "-nightly".to_string()), Some(tag_name) => (false, format!("-{tag_name}")), None => (false, "-dev".to_string()), };