From 3300f41bc25b37c85baa30fee53cacd6e92b7901 Mon Sep 17 00:00:00 2001 From: charisma98 Date: Fri, 18 Feb 2022 00:20:03 +0200 Subject: [PATCH] fix(bind): make more ergonomic --- Cargo.lock | 22 +++++++++++----------- cli/src/cmd/bind.rs | 31 +++++++++++-------------------- 2 files changed, 22 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3e76d225..dd649fe7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1154,7 +1154,7 @@ dependencies = [ [[package]] name = "ethers" version = "0.6.0" -source = "git+https://github.com/gakonst/ethers-rs#19d2fd115529ec18652f2ce544a9e52d70047883" +source = "git+https://github.com/gakonst/ethers-rs#16b9de513497c0c0d165011fcb1d7f920af6d6a8" dependencies = [ "ethers-addressbook", "ethers-contract", @@ -1169,7 +1169,7 @@ dependencies = [ [[package]] name = "ethers-addressbook" version = "0.1.0" -source = "git+https://github.com/gakonst/ethers-rs#19d2fd115529ec18652f2ce544a9e52d70047883" +source = "git+https://github.com/gakonst/ethers-rs#16b9de513497c0c0d165011fcb1d7f920af6d6a8" dependencies = [ "ethers-core", "once_cell", @@ -1180,7 +1180,7 @@ dependencies = [ [[package]] name = "ethers-contract" version = "0.6.0" -source = "git+https://github.com/gakonst/ethers-rs#19d2fd115529ec18652f2ce544a9e52d70047883" +source = "git+https://github.com/gakonst/ethers-rs#16b9de513497c0c0d165011fcb1d7f920af6d6a8" dependencies = [ "ethers-contract-abigen", "ethers-contract-derive", @@ -1198,7 +1198,7 @@ dependencies = [ [[package]] name = "ethers-contract-abigen" version = "0.6.0" -source = "git+https://github.com/gakonst/ethers-rs#19d2fd115529ec18652f2ce544a9e52d70047883" +source = "git+https://github.com/gakonst/ethers-rs#16b9de513497c0c0d165011fcb1d7f920af6d6a8" dependencies = [ "Inflector", "cfg-if 1.0.0", @@ -1221,7 +1221,7 @@ dependencies = [ [[package]] name = "ethers-contract-derive" version = "0.6.0" -source = "git+https://github.com/gakonst/ethers-rs#19d2fd115529ec18652f2ce544a9e52d70047883" +source = "git+https://github.com/gakonst/ethers-rs#16b9de513497c0c0d165011fcb1d7f920af6d6a8" dependencies = [ "ethers-contract-abigen", "ethers-core", @@ -1235,7 +1235,7 @@ dependencies = [ [[package]] name = "ethers-core" version = "0.6.0" -source = "git+https://github.com/gakonst/ethers-rs#19d2fd115529ec18652f2ce544a9e52d70047883" +source = "git+https://github.com/gakonst/ethers-rs#16b9de513497c0c0d165011fcb1d7f920af6d6a8" dependencies = [ "arrayvec 0.7.2", "bytes", @@ -1263,7 +1263,7 @@ dependencies = [ [[package]] name = "ethers-etherscan" version = "0.2.0" -source = "git+https://github.com/gakonst/ethers-rs#19d2fd115529ec18652f2ce544a9e52d70047883" +source = "git+https://github.com/gakonst/ethers-rs#16b9de513497c0c0d165011fcb1d7f920af6d6a8" dependencies = [ "ethers-core", "ethers-solc", @@ -1277,7 +1277,7 @@ dependencies = [ [[package]] name = "ethers-middleware" version = "0.6.0" -source = "git+https://github.com/gakonst/ethers-rs#19d2fd115529ec18652f2ce544a9e52d70047883" +source = "git+https://github.com/gakonst/ethers-rs#16b9de513497c0c0d165011fcb1d7f920af6d6a8" dependencies = [ "async-trait", "ethers-contract", @@ -1300,7 +1300,7 @@ dependencies = [ [[package]] name = "ethers-providers" version = "0.6.0" -source = "git+https://github.com/gakonst/ethers-rs#19d2fd115529ec18652f2ce544a9e52d70047883" +source = "git+https://github.com/gakonst/ethers-rs#16b9de513497c0c0d165011fcb1d7f920af6d6a8" dependencies = [ "async-trait", "auto_impl", @@ -1332,7 +1332,7 @@ dependencies = [ [[package]] name = "ethers-signers" version = "0.6.0" -source = "git+https://github.com/gakonst/ethers-rs#19d2fd115529ec18652f2ce544a9e52d70047883" +source = "git+https://github.com/gakonst/ethers-rs#16b9de513497c0c0d165011fcb1d7f920af6d6a8" dependencies = [ "async-trait", "coins-bip32", @@ -1355,7 +1355,7 @@ dependencies = [ [[package]] name = "ethers-solc" version = "0.3.0" -source = "git+https://github.com/gakonst/ethers-rs#19d2fd115529ec18652f2ce544a9e52d70047883" +source = "git+https://github.com/gakonst/ethers-rs#16b9de513497c0c0d165011fcb1d7f920af6d6a8" dependencies = [ "colored", "dunce", diff --git a/cli/src/cmd/bind.rs b/cli/src/cmd/bind.rs index 60249987..73cf6783 100644 --- a/cli/src/cmd/bind.rs +++ b/cli/src/cmd/bind.rs @@ -31,20 +31,12 @@ pub struct BindArgs { #[clap( help = "Path to where the contract artifacts are stored", - long = "out", + long = "bindings-path", short, value_hint = ValueHint::DirPath )] - #[serde(rename = "out", skip_serializing_if = "Option::is_none")] - pub out_path: Option, - - #[clap( - help = "A directory at which to write the generated rust crate", - long = "bindings-root", - value_hint = ValueHint::DirPath - )] #[serde(skip)] - pub bindings_root: Option, + pub bindings: Option, #[clap( long = "crate-name", @@ -62,6 +54,9 @@ pub struct BindArgs { #[serde(skip)] crate_version: String, + #[clap(long, help = "Generate the bindings as a module instead of a crate")] + module: bool, + #[clap( long = "overwrite", help = "Overwrite existing generated bindings. If set to false, the command will check that the bindings are correct, and then exit. If set to true, it will instead delete and overwrite the bindings." @@ -83,12 +78,7 @@ impl BindArgs { /// Get the path to the root of the autogenerated crate fn bindings_root(&self) -> PathBuf { - self.bindings_root.clone().unwrap_or_else(|| self.artifacts().join("bindings")) - } - - /// `true` if the arguments set `crate_version` or `crate_name` - fn gen_crate(&self) -> bool { - self.crate_name != DEFAULT_CRATE_NAME || self.crate_version != DEFAULT_CRATE_VERSION + self.bindings.clone().unwrap_or_else(|| self.artifacts().join("bindings")) } /// `true` if the bindings root already exists @@ -103,7 +93,7 @@ impl BindArgs { eyre::ensure!( !multi.is_empty(), r#" - No contract artifacts found. Hint: Have you built your contracts yet? `forge bind` does not currently invoke `forge build`, although this is planned for future versions. +No contract artifacts found. Hint: Have you built your contracts yet? `forge bind` does not currently invoke `forge build`, although this is planned for future versions. "# ); Ok(multi) @@ -112,8 +102,8 @@ impl BindArgs { /// Check that the existing bindings match the expected abigen output fn check_existing_bindings(&self) -> eyre::Result<()> { let bindings = self.get_multi()?.build()?; - println!("Checking bindings for {} contracts", bindings.len()); - if self.gen_crate() { + println!("Checking bindings for {} contracts.", bindings.len()); + if !self.module { bindings.ensure_consistent_crate( &self.crate_name, &self.crate_version, @@ -123,6 +113,7 @@ impl BindArgs { } else { bindings.ensure_consistent_module(self.bindings_root(), self.single_file)?; } + println!("OK."); Ok(()) } @@ -130,7 +121,7 @@ impl BindArgs { fn generate_bindings(&self) -> eyre::Result<()> { let bindings = self.get_multi()?.build()?; println!("Generating bindings for {} contracts", bindings.len()); - if self.gen_crate() { + if !self.module { bindings.write_to_crate( &self.crate_name, &self.crate_version,