Skip to content

Commit

Permalink
provide way for users to mute the warning by setting a FOUNDRY_DISABL…
Browse files Browse the repository at this point in the history
…E_NIGHTLY_WARNING environment variable
  • Loading branch information
zerosnacks committed Jan 15, 2025
1 parent d980cc1 commit 3811996
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions crates/cli/src/opts/global.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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);
}

Expand Down
8 changes: 4 additions & 4 deletions crates/common/src/version.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -13,9 +15,7 @@ pub fn set_build_version() -> Result<(), Box<dyn Error>> {
// if on a tag: <BIN> 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()),
};
Expand Down

0 comments on commit 3811996

Please sign in to comment.