Skip to content

chore(forge): enforce common::shell for forge crate #9231

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

Merged
merged 8 commits into from
Nov 4, 2024
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
3 changes: 1 addition & 2 deletions crates/cast/bin/cmd/create2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ impl Create2Args {

sh_println!("Configuration:")?;
sh_println!("Init code hash: {init_code_hash}")?;
sh_println!("Regex patterns: {:?}", regex.patterns())?;
sh_println!()?;
sh_println!("Regex patterns: {:?}\n", regex.patterns())?;
sh_println!(
"Starting to generate deterministic contract address with {n_threads} threads..."
)?;
Expand Down
23 changes: 11 additions & 12 deletions crates/forge/bin/cmd/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,9 @@ impl BindArgs {
}

if self.ethers {
eprintln!(
"Warning: `--ethers` bindings are deprecated and will be removed in the future. \
Consider using `--alloy` (default) instead."
);
sh_warn!(
"`--ethers` bindings are deprecated and will be removed in the future. Consider using `--alloy` (default) instead."
)?;
}

let config = self.try_load_config_emit_warnings()?;
Expand All @@ -118,7 +117,7 @@ impl BindArgs {

if bindings_root.exists() {
if !self.overwrite {
println!("Bindings found. Checking for consistency.");
sh_println!("Bindings found. Checking for consistency.")?;
return self.check_existing_bindings(&artifacts, &bindings_root);
}

Expand All @@ -128,7 +127,7 @@ impl BindArgs {

self.generate_bindings(&artifacts, &bindings_root)?;

println!("Bindings have been generated to {}", bindings_root.display());
sh_println!("Bindings have been generated to {}", bindings_root.display())?;
Ok(())
}

Expand Down Expand Up @@ -274,7 +273,7 @@ impl BindArgs {

fn check_ethers(&self, artifacts: &Path, bindings_root: &Path) -> Result<()> {
let bindings = self.get_multi(artifacts)?.build()?;
println!("Checking bindings for {} contracts.", bindings.len());
sh_println!("Checking bindings for {} contracts.", bindings.len())?;
if !self.module {
bindings
.ensure_consistent_crate(
Expand All @@ -294,14 +293,14 @@ impl BindArgs {
} else {
bindings.ensure_consistent_module(bindings_root, self.single_file)?;
}
println!("OK.");
sh_println!("OK.")?;
Ok(())
}

fn check_alloy(&self, artifacts: &Path, bindings_root: &Path) -> Result<()> {
let mut bindings = self.get_solmacrogen(artifacts)?;
bindings.generate_bindings()?;
println!("Checking bindings for {} contracts", bindings.instances.len());
sh_println!("Checking bindings for {} contracts", bindings.instances.len())?;
bindings.check_consistency(
&self.crate_name,
&self.crate_version,
Expand All @@ -311,7 +310,7 @@ impl BindArgs {
self.module,
self.alloy_version.clone(),
)?;
println!("OK.");
sh_println!("OK.")?;
Ok(())
}

Expand All @@ -326,7 +325,7 @@ impl BindArgs {

fn generate_ethers(&self, artifacts: &Path, bindings_root: &Path) -> Result<()> {
let mut bindings = self.get_multi(artifacts)?.build()?;
println!("Generating bindings for {} contracts", bindings.len());
sh_println!("Generating bindings for {} contracts", bindings.len())?;
if !self.module {
trace!(single_file = self.single_file, "generating crate");
if !self.skip_extra_derives {
Expand All @@ -346,7 +345,7 @@ impl BindArgs {

fn generate_alloy(&self, artifacts: &Path, bindings_root: &Path) -> Result<()> {
let mut solmacrogen = self.get_solmacrogen(artifacts)?;
println!("Generating bindings for {} contracts", solmacrogen.instances.len());
sh_println!("Generating bindings for {} contracts", solmacrogen.instances.len())?;

if !self.module {
trace!(single_file = self.single_file, "generating crate");
Expand Down
2 changes: 1 addition & 1 deletion crates/forge/bin/cmd/bind_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ impl ResolvedState {
}
fs::write(&self.target_path, &result)?;

println!("Bindings written to {}", self.target_path.display());
sh_println!("Bindings written to {}", self.target_path.display())?;

Ok(result)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/forge/bin/cmd/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl LsArgs {
ChainOrAll::All => cache = Config::list_foundry_cache()?,
}
}
print!("{cache}");
sh_print!("{cache}")?;
Ok(())
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/forge/bin/cmd/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ mod tests {
use foundry_test_utils::rpc::next_mainnet_etherscan_api_key;
use std::collections::BTreeMap;

#[allow(clippy::disallowed_macros)]
fn assert_successful_compilation(root: &PathBuf) -> ProjectCompileOutput {
println!("project_root: {root:#?}");
compile_project(root).expect("compilation failure")
Expand Down
18 changes: 9 additions & 9 deletions crates/forge/bin/cmd/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,25 +141,25 @@ impl ResolveArgs {
}

if json {
println!("{}", serde_json::to_string(&output)?);
sh_println!("{}", serde_json::to_string(&output)?)?;
return Ok(());
}

for (language, compilers) in &output {
match verbosity {
0 => println!("{language}:"),
_ => println!("{language}:\n"),
0 => sh_println!("{language}:")?,
_ => sh_println!("{language}:\n")?,
}

for resolved_compiler in compilers {
let version = &resolved_compiler.version;
match verbosity {
0 => println!("- {version}"),
0 => sh_println!("- {version}")?,
_ => {
if let Some(evm) = &resolved_compiler.evm_version {
println!("{version} (<= {evm}):")
sh_println!("{version} (<= {evm}):")?
} else {
println!("{version}:")
sh_println!("{version}:")?
}
}
}
Expand All @@ -168,16 +168,16 @@ impl ResolveArgs {
let paths = &resolved_compiler.paths;
for (idx, path) in paths.iter().enumerate() {
if idx == paths.len() - 1 {
println!("└── {path}\n");
sh_println!("└── {path}\n")?
} else {
println!("├── {path}");
sh_println!("├── {path}")?
}
}
}
}

if verbosity == 0 {
println!();
sh_println!()?
}
}

Expand Down
12 changes: 6 additions & 6 deletions crates/forge/bin/cmd/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,18 +318,18 @@ impl CreateArgs {
"deployedTo": address.to_string(),
"transactionHash": receipt.transaction_hash
});
println!("{output}");
sh_println!("{output}")?;
} else {
println!("Deployer: {deployer_address}");
println!("Deployed to: {address}");
println!("Transaction hash: {:?}", receipt.transaction_hash);
sh_println!("Deployer: {deployer_address}")?;
sh_println!("Deployed to: {address}")?;
sh_println!("Transaction hash: {:?}", receipt.transaction_hash)?;
};

if !self.verify {
return Ok(());
}

println!("Starting contract verification...");
sh_println!("Starting contract verification...")?;

let num_of_optimizations = if self.opts.compiler.optimize.unwrap_or_default() {
self.opts.compiler.optimizer_runs
Expand Down Expand Up @@ -358,7 +358,7 @@ impl CreateArgs {
show_standard_json_input: self.show_standard_json_input,
guess_constructor_args: false,
};
println!("Waiting for {} to detect contract deployment...", verify.verifier.verifier);
sh_println!("Waiting for {} to detect contract deployment...", verify.verifier.verifier)?;
verify.run().await
}

Expand Down
2 changes: 1 addition & 1 deletion crates/forge/bin/cmd/doc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Server {
let file_404 = get_404_output_file(&input_404);

let serving_url = format!("http://{address}");
println!("Serving on: {serving_url}");
sh_println!("Serving on: {serving_url}")?;

let thread_handle = std::thread::spawn(move || serve(build_dir, sockaddr, &file_404));

Expand Down
3 changes: 1 addition & 2 deletions crates/forge/bin/cmd/eip712.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ impl Eip712Args {

for (id, _) in structs_in_target {
if let Some(resolved) = resolver.resolve_struct_eip712(id)? {
println!("{resolved}");
println!();
sh_println!("{resolved}\n")?;
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/forge/bin/cmd/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ impl FlattenArgs {
Some(output) => {
fs::create_dir_all(output.parent().unwrap())?;
fs::write(&output, flattened)?;
println!("Flattened file written at {}", output.display());
sh_println!("Flattened file written at {}", output.display())?;
}
None => println!("{flattened}"),
None => sh_println!("{flattened}")?,
};

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/forge/bin/cmd/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl FmtArgs {
let new_format = diff.ratio() < 1.0;
if self.check || path.is_none() {
if self.raw {
print!("{output}");
sh_print!("{output}")?;
}

// If new format then compute diff summary.
Expand Down
7 changes: 3 additions & 4 deletions crates/forge/bin/cmd/geiger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use foundry_config::{impl_figment_convert_basic, Config};
use itertools::Itertools;
use rayon::prelude::*;
use std::path::PathBuf;
use yansi::Paint;

mod error;

Expand Down Expand Up @@ -95,7 +94,7 @@ impl GeigerArgs {
let sources = self.sources(&config).wrap_err("Failed to resolve files")?;

if config.ffi {
eprintln!("{}\n", "ffi enabled".red());
sh_warn!("FFI enabled\n")?;
}

let root = config.root.0;
Expand All @@ -107,12 +106,12 @@ impl GeigerArgs {
let len = metrics.cheatcodes.len();
let printer = SolFileMetricsPrinter { metrics: &metrics, root: &root };
if self.full || len == 0 {
eprint!("{printer}");
let _ = sh_eprint!("{printer}");
}
len
}
Err(err) => {
eprintln!("{err}");
let _ = sh_err!("{err}");
0
}
})
Expand Down
2 changes: 1 addition & 1 deletion crates/forge/bin/cmd/generate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl GenerateTestArgs {
// Write the test content to the test file.
fs::write(&test_file_path, test_content)?;

println!("{} test file: {}", "Generated".green(), test_file_path.to_str().unwrap());
sh_println!("{} test file: {}", "Generated".green(), test_file_path.to_str().unwrap())?;
Ok(())
}
}
Expand Down
14 changes: 7 additions & 7 deletions crates/forge/bin/cmd/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl InspectArgs {
.ok_or_else(|| eyre::eyre!("Failed to fetch lossless ABI"))?;
if pretty {
let source = foundry_cli::utils::abi_to_solidity(abi, &contract.name)?;
println!("{source}");
sh_println!("{source}")?;
} else {
print_json(abi)?;
}
Expand Down Expand Up @@ -201,7 +201,7 @@ pub fn print_storage_layout(storage_layout: Option<&StorageLayout>, pretty: bool
]);
}

println!("{table}");
sh_println!("{table}")?;
Ok(())
}

Expand Down Expand Up @@ -390,12 +390,12 @@ impl ContractArtifactField {
}

fn print_json(obj: &impl serde::Serialize) -> Result<()> {
println!("{}", serde_json::to_string_pretty(obj)?);
sh_println!("{}", serde_json::to_string_pretty(obj)?)?;
Ok(())
}

fn print_json_str(obj: &impl serde::Serialize, key: Option<&str>) -> Result<()> {
println!("{}", get_json_str(obj, key)?);
sh_println!("{}", get_json_str(obj, key)?)?;
Ok(())
}

Expand All @@ -408,9 +408,9 @@ fn print_yul(yul: Option<&str>, pretty: bool) -> Result<()> {
LazyLock::new(|| Regex::new(r"(///.*\n\s*)|(\s*/\*\*.*\*/)").unwrap());

if pretty {
println!("{}", YUL_COMMENTS.replace_all(yul, ""));
sh_println!("{}", YUL_COMMENTS.replace_all(yul, ""))?;
} else {
println!("{yul}");
sh_println!("{yul}")?;
}

Ok(())
Expand Down Expand Up @@ -450,7 +450,7 @@ fn print_eof(bytecode: Option<CompactBytecode>) -> Result<()> {

let eof = Eof::decode(bytecode).wrap_err("Failed to decode EOF")?;

println!("{}", pretty_eof(&eof)?);
sh_println!("{}", pretty_eof(&eof)?)?;

Ok(())
}
Expand Down
14 changes: 7 additions & 7 deletions crates/forge/bin/cmd/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,9 @@ impl Installer<'_> {

// multiple candidates, ask the user to choose one or skip
candidates.insert(0, String::from("SKIP AND USE ORIGINAL TAG"));
println!("There are multiple matching tags:");
sh_println!("There are multiple matching tags:")?;
for (i, candidate) in candidates.iter().enumerate() {
println!("[{i}] {candidate}");
sh_println!("[{i}] {candidate}")?;
}

let n_candidates = candidates.len();
Expand All @@ -429,7 +429,7 @@ impl Installer<'_> {
Ok(0) => return Ok(tag.into()),
Ok(i) if (1..=n_candidates).contains(&i) => {
let c = &candidates[i];
println!("[{i}] {c} selected");
sh_println!("[{i}] {c} selected")?;
return Ok(c.clone())
}
_ => continue,
Expand Down Expand Up @@ -474,9 +474,9 @@ impl Installer<'_> {

// multiple candidates, ask the user to choose one or skip
candidates.insert(0, format!("{tag} (original branch)"));
println!("There are multiple matching branches:");
sh_println!("There are multiple matching branches:")?;
for (i, candidate) in candidates.iter().enumerate() {
println!("[{i}] {candidate}");
sh_println!("[{i}] {candidate}")?;
}

let n_candidates = candidates.len();
Expand All @@ -488,7 +488,7 @@ impl Installer<'_> {

// default selection, return None
if input.is_empty() {
println!("Canceled branch matching");
sh_println!("Canceled branch matching")?;
return Ok(None)
}

Expand All @@ -497,7 +497,7 @@ impl Installer<'_> {
Ok(0) => Ok(Some(tag.into())),
Ok(i) if (1..=n_candidates).contains(&i) => {
let c = &candidates[i];
println!("[{i}] {c} selected");
sh_println!("[{i}] {c} selected")?;
Ok(Some(c.clone()))
}
_ => Ok(None),
Expand Down
Loading
Loading