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(forge): --profile to set the profile via CLI #9427

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
36 changes: 33 additions & 3 deletions crates/cli/src/opts/build/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ use foundry_compilers::{
Project,
};
use foundry_config::{
figment,
figment::{
self,
error::Kind::InvalidType,
value::{Dict, Map, Value},
Figment, Metadata, Profile, Provider,
},
filter::SkipBuildFilter,
get_available_profiles,
providers::remappings::Remappings,
Config,
Config, RootPath,
};
use serde::Serialize;
use std::path::PathBuf;
Expand Down Expand Up @@ -144,6 +145,10 @@ pub struct CoreBuildArgs {
#[command(flatten)]
#[serde(flatten)]
pub project_paths: ProjectPathsArgs,

/// Profile to use for compiling the project.
#[arg(long)]
pub profile: Option<Profile>,
Copy link
Member

Choose a reason for hiding this comment

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

I think we can have this in the global args and make it initialize Config::selected_profile

}

impl CoreBuildArgs {
Expand Down Expand Up @@ -193,6 +198,25 @@ impl<'a> From<&'a CoreBuildArgs> for Figment {
figment = figment.merge(("skip", skip));
};

if let Some(profile) = &args.profile {
let root = figment.extract_inner::<RootPath>("root").unwrap_or_default();

let config_path = root.0.join(Config::FILE_NAME);

let available_profiles = get_available_profiles(&config_path).unwrap_or_default();

if !available_profiles.contains(&profile.to_string()) {
let _ = sh_warn!(
"Profile `{}` not found in available profiles `{:?}`. Using {} profile",
profile,
available_profiles,
figment.profile(),
);
} else {
figment = figment.select(profile.clone());
}
}

figment
}
}
Expand Down Expand Up @@ -286,6 +310,12 @@ impl Provider for CoreBuildArgs {
dict.insert("eof".to_string(), true.into());
}

Ok(Map::from([(Config::selected_profile(), dict)]))
let profile = if let Some(profile) = &self.profile {
profile.clone()
} else {
Config::selected_profile()
};

Ok(Map::from([(profile, dict)]))
}
}
Loading