Skip to content

Commit 4f661a9

Browse files
authored
chore(cli): remove Cmd trait (foundry-rs#5614)
1 parent 27fcc1a commit 4f661a9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+275
-333
lines changed

crates/cli/src/cast/cmd/access_list.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use ethers::{
44
providers::Middleware,
55
types::{BlockId, NameOrAddress},
66
};
7-
use eyre::WrapErr;
7+
use eyre::{Result, WrapErr};
88
use foundry_cli::{
99
opts::{EthereumOpts, TransactionOpts},
1010
utils,
@@ -57,7 +57,7 @@ pub struct AccessListArgs {
5757
}
5858

5959
impl AccessListArgs {
60-
pub async fn run(self) -> eyre::Result<()> {
60+
pub async fn run(self) -> Result<()> {
6161
let AccessListArgs { to, sig, args, data, tx, eth, block, json: to_json } = self;
6262

6363
let config = Config::from(&eth);
@@ -82,7 +82,7 @@ async fn access_list<M: Middleware, F: Into<NameOrAddress>, T: Into<NameOrAddres
8282
chain: Chain,
8383
block: Option<BlockId>,
8484
to_json: bool,
85-
) -> eyre::Result<()>
85+
) -> Result<()>
8686
where
8787
M::Error: 'static,
8888
{

crates/cli/src/cast/cmd/call.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use ethers::{
44
solc::EvmVersion,
55
types::{BlockId, NameOrAddress, U256},
66
};
7-
use eyre::WrapErr;
7+
use eyre::{Result, WrapErr};
88
use forge::executor::opts::EvmOpts;
99
use foundry_cli::{
1010
opts::{EthereumOpts, TransactionOpts},
@@ -108,7 +108,7 @@ pub enum CallSubcommands {
108108
}
109109

110110
impl CallArgs {
111-
pub async fn run(self) -> eyre::Result<()> {
111+
pub async fn run(self) -> Result<()> {
112112
let CallArgs {
113113
to,
114114
sig,
@@ -224,7 +224,7 @@ async fn fill_create(
224224
code: String,
225225
sig: Option<String>,
226226
args: Vec<String>,
227-
) -> eyre::Result<()> {
227+
) -> Result<()> {
228228
builder.value(value);
229229

230230
let mut data = hex::decode(code.strip_prefix("0x").unwrap_or(&code))?;
@@ -246,7 +246,7 @@ async fn fill_tx(
246246
sig: Option<String>,
247247
args: Vec<String>,
248248
data: Option<String>,
249-
) -> eyre::Result<()> {
249+
) -> Result<()> {
250250
builder.value(value);
251251

252252
if let Some(sig) = sig {

crates/cli/src/cast/cmd/create2.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use ethers::{
66
utils::{get_create2_address_from_hash, keccak256},
77
};
88
use eyre::{Result, WrapErr};
9-
use foundry_cli::utils::Cmd;
109
use rayon::prelude::*;
1110
use regex::RegexSetBuilder;
1211
use std::{str::FromStr, time::Instant};
@@ -59,16 +58,8 @@ pub struct Create2Output {
5958
pub salt: U256,
6059
}
6160

62-
impl Cmd for Create2Args {
63-
type Output = Create2Output;
64-
65-
fn run(self) -> eyre::Result<Self::Output> {
66-
Create2Args::generate_address(self)
67-
}
68-
}
69-
7061
impl Create2Args {
71-
fn generate_address(self) -> Result<Create2Output> {
62+
pub fn run(self) -> Result<Create2Output> {
7263
let Create2Args {
7364
starts_with,
7465
ends_with,

crates/cli/src/cast/cmd/interface.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use cast::{AbiPath, SimpleCast};
22
use clap::Parser;
3+
use eyre::Result;
34
use foundry_cli::opts::EtherscanOpts;
45
use foundry_common::fs;
56
use foundry_config::Config;
@@ -37,7 +38,7 @@ pub struct InterfaceArgs {
3738
}
3839

3940
impl InterfaceArgs {
40-
pub async fn run(self) -> eyre::Result<()> {
41+
pub async fn run(self) -> Result<()> {
4142
let InterfaceArgs { path_or_address, name, pragma, output: output_location, etherscan } =
4243
self;
4344
let config = Config::from(&etherscan);

crates/cli/src/cast/cmd/logs.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ use ethers::{
55
providers::Middleware,
66
types::{BlockId, BlockNumber, Filter, FilterBlockOption, NameOrAddress, ValueOrArray, H256},
77
};
8+
use eyre::Result;
89
use foundry_cli::{opts::EthereumOpts, utils};
9-
1010
use foundry_common::abi::{get_event, parse_tokens};
1111
use foundry_config::Config;
12-
1312
use itertools::Itertools;
14-
1513
use std::str::FromStr;
1614

1715
/// CLI arguments for `cast logs`.
@@ -55,7 +53,7 @@ pub struct LogsArgs {
5553
}
5654

5755
impl LogsArgs {
58-
pub async fn run(self) -> eyre::Result<()> {
56+
pub async fn run(self) -> Result<()> {
5957
let LogsArgs {
6058
from_block, to_block, address, topics_or_args, sig_or_topic, json, eth, ..
6159
} = self;

crates/cli/src/cast/cmd/run.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clap::Parser;
22
use ethers::{prelude::Middleware, solc::EvmVersion, types::H160};
3-
use eyre::WrapErr;
3+
use eyre::{Result, WrapErr};
44
use forge::{
55
executor::{inspector::cheatcodes::util::configure_tx_env, opts::EvmOpts},
66
revm::primitives::U256 as rU256,
@@ -82,7 +82,7 @@ impl RunArgs {
8282
/// This replays the entire block the transaction was mined in unless `quick` is set to true
8383
///
8484
/// Note: This executes the transaction(s) as is: Cheatcodes are disabled
85-
pub async fn run(self) -> eyre::Result<()> {
85+
pub async fn run(self) -> Result<()> {
8686
let figment =
8787
Config::figment_with_root(find_project_root_path(None).unwrap()).merge(self.rpc);
8888
let evm_opts = figment.extract::<EvmOpts>()?;

crates/cli/src/cast/cmd/send.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use clap::Parser;
33
use ethers::{
44
prelude::MiddlewareBuilder, providers::Middleware, signers::Signer, types::NameOrAddress,
55
};
6+
use eyre::Result;
67
use foundry_cli::{
78
opts::{EthereumOpts, TransactionOpts},
89
utils,
@@ -73,7 +74,7 @@ pub enum SendTxSubcommands {
7374
}
7475

7576
impl SendTxArgs {
76-
pub async fn run(self) -> eyre::Result<()> {
77+
pub async fn run(self) -> Result<()> {
7778
let SendTxArgs {
7879
eth,
7980
to,
@@ -208,7 +209,7 @@ async fn cast_send<M: Middleware, F: Into<NameOrAddress>, T: Into<NameOrAddress>
208209
cast_async: bool,
209210
confs: usize,
210211
to_json: bool,
211-
) -> eyre::Result<()>
212+
) -> Result<()>
212213
where
213214
M::Error: 'static,
214215
{

crates/cli/src/cast/cmd/wallet/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ use ethers::{
55
signers::{LocalWallet, Signer},
66
types::{transaction::eip712::TypedData, Address, Signature},
77
};
8-
use eyre::Context;
9-
use foundry_cli::{
10-
opts::{RawWallet, Wallet},
11-
utils::Cmd,
12-
};
8+
use eyre::{Context, Result};
9+
use foundry_cli::opts::{RawWallet, Wallet};
1310
use foundry_common::fs;
1411
use foundry_config::Config;
1512
use std::path::Path;
@@ -120,7 +117,7 @@ pub enum WalletSubcommands {
120117
}
121118

122119
impl WalletSubcommands {
123-
pub async fn run(self) -> eyre::Result<()> {
120+
pub async fn run(self) -> Result<()> {
124121
match self {
125122
WalletSubcommands::New { path, unsafe_password, .. } => {
126123
let mut rng = thread_rng();
@@ -281,7 +278,7 @@ flag to set your key via:
281278
Ok(())
282279
}
283280

284-
fn hex_str_to_bytes(s: &str) -> eyre::Result<Vec<u8>> {
281+
fn hex_str_to_bytes(s: &str) -> Result<Vec<u8>> {
285282
Ok(match s.strip_prefix("0x") {
286283
Some(data) => hex::decode(data).wrap_err("Could not decode 0x-prefixed string.")?,
287284
None => s.as_bytes().to_vec(),

crates/cli/src/cast/cmd/wallet/vanity.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use ethers::{
66
types::{H160, U256},
77
utils::{get_contract_address, secret_key_to_address},
88
};
9-
use foundry_cli::utils::Cmd;
9+
use eyre::Result;
10+
1011
use rayon::iter::{self, ParallelIterator};
1112
use regex::Regex;
1213
use std::time::Instant;
@@ -37,10 +38,8 @@ pub struct VanityArgs {
3738
pub nonce: Option<u64>,
3839
}
3940

40-
impl Cmd for VanityArgs {
41-
type Output = LocalWallet;
42-
43-
fn run(self) -> eyre::Result<Self::Output> {
41+
impl VanityArgs {
42+
pub fn run(self) -> Result<LocalWallet> {
4443
let Self { starts_with, ends_with, nonce } = self;
4544
let mut left_exact_hex = None;
4645
let mut left_regex = None;

crates/cli/src/cast/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use ethers::{
77
types::Address,
88
utils::keccak256,
99
};
10-
use foundry_cli::{handler, prompt, stdin, utils, utils::Cmd};
10+
use eyre::Result;
11+
use foundry_cli::{handler, prompt, stdin, utils};
1112
use foundry_common::{
1213
abi::{format_tokens, get_event},
1314
fs,
@@ -25,7 +26,7 @@ pub mod opts;
2526
use opts::{Opts, Subcommands, ToBaseArgs};
2627

2728
#[tokio::main]
28-
async fn main() -> eyre::Result<()> {
29+
async fn main() -> Result<()> {
2930
utils::load_dotenv();
3031
handler::install()?;
3132
utils::subscriber();

0 commit comments

Comments
 (0)