Skip to content

Commit

Permalink
tx proxy gen - remove overwrite command
Browse files Browse the repository at this point in the history
  • Loading branch information
BiancaIalangi committed Mar 19, 2024
1 parent 556468b commit 1869010
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 38 deletions.
21 changes: 2 additions & 19 deletions framework/meta/src/cli_args/cli_args_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub enum ContractCliAction {
name = "proxy",
about = "Generates a proxy, based on the contract ABI."
)]
GenerateProxies(GenerateProxyArgs),
GenerateProxies,
}

impl CliArgsToRaw for ContractCliAction {
Expand Down Expand Up @@ -103,9 +103,8 @@ impl CliArgsToRaw for ContractCliAction {
raw.push("snippets".to_string());
raw.append(&mut args.to_raw());
},
ContractCliAction::GenerateProxies(args) => {
ContractCliAction::GenerateProxies => {
raw.push("proxy".to_string());
raw.append(&mut args.to_raw());
},
}
raw
Expand All @@ -128,19 +127,3 @@ impl CliArgsToRaw for GenerateSnippetsArgs {
raw
}
}
#[derive(Default, Clone, PartialEq, Eq, Debug, Args)]
pub struct GenerateProxyArgs {
/// Override TxProxy project if it already exists.
#[arg(long, verbatim_doc_comment)]
pub overwrite: bool,
}

impl CliArgsToRaw for GenerateProxyArgs {
fn to_raw(&self) -> Vec<String> {
let mut raw = Vec::new();
if self.overwrite {
raw.push("--overwrite".to_string());
}
raw
}
}
4 changes: 1 addition & 3 deletions framework/meta/src/cmd/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ pub fn cli_main<AbiObj: ContractAbiProvider>() {
ContractCliAction::GenerateSnippets(gs_arg) => {
meta_config_opt.generate_rust_snippets(&gs_arg)
},
ContractCliAction::GenerateProxies(arg) => {
meta_config_opt.generate_rust_proxies_struct(&arg)
},
ContractCliAction::GenerateProxies => meta_config_opt.generate_proxy(),
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
use std::fs::File;

#[must_use]
pub(crate) fn create_file(proxies_file_name: &str, overwrite: bool) -> File {
pub(crate) fn create_file(proxies_file_name: &str) -> File {
let file = format!("../{proxies_file_name}");

if overwrite {
File::create(&file).expect("could not write proxy file")
} else {
match File::options().create_new(true).write(true).open(&file) {
Ok(f) => f,
Err(_) => panic!("{file} file already exists, --overwrite option was not provided"),
}
}
File::create(&file).expect("could not write proxy file")

Check warning on line 7 in framework/meta/src/cmd/contract/generate_proxy/proxy_crate_gen.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] framework/meta/src/cmd/contract/generate_proxy/proxy_crate_gen.rs#L7

warning: the borrowed expression implements the required traits --> framework/meta/src/cmd/contract/generate_proxy/proxy_crate_gen.rs:7:18 | 7 | File::create(&file).expect("could not write proxy file") | ^^^^^ help: change this to: `file` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args = note: `#[warn(clippy::needless_borrows_for_generic_args)]` on by default
Raw output
framework/meta/src/cmd/contract/generate_proxy/proxy_crate_gen.rs:7:18:w:warning: the borrowed expression implements the required traits
 --> framework/meta/src/cmd/contract/generate_proxy/proxy_crate_gen.rs:7:18
  |
7 |     File::create(&file).expect("could not write proxy file")
  |                  ^^^^^ help: change this to: `file`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
  = note: `#[warn(clippy::needless_borrows_for_generic_args)]` on by default


__END__

Check warning on line 7 in framework/meta/src/cmd/contract/generate_proxy/proxy_crate_gen.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] framework/meta/src/cmd/contract/generate_proxy/proxy_crate_gen.rs#L7

warning: the borrowed expression implements the required traits --> framework/meta/src/cmd/contract/generate_proxy/proxy_crate_gen.rs:7:18 | 7 | File::create(&file).expect("could not write proxy file") | ^^^^^ help: change this to: `file` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args = note: `#[warn(clippy::needless_borrows_for_generic_args)]` on by default
Raw output
framework/meta/src/cmd/contract/generate_proxy/proxy_crate_gen.rs:7:18:w:warning: the borrowed expression implements the required traits
 --> framework/meta/src/cmd/contract/generate_proxy/proxy_crate_gen.rs:7:18
  |
7 |     File::create(&file).expect("could not write proxy file")
  |                  ^^^^^ help: change this to: `file`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrows_for_generic_args
  = note: `#[warn(clippy::needless_borrows_for_generic_args)]` on by default


__END__
}
12 changes: 5 additions & 7 deletions framework/meta/src/cmd/contract/generate_proxy/proxy_gen_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use std::fs::File;

use multiversx_sc::abi::ContractAbi;

use crate::cli_args::GenerateProxyArgs;

use super::{
super::meta_config::MetaConfig,
proxy_crate_gen::create_file,
Expand All @@ -16,16 +14,16 @@ use super::{
const PROXIES_SOURCE_FILE_NAME: &str = "/output/proxy.rs";

impl MetaConfig {
pub fn generate_rust_proxies_struct(&self, args: &GenerateProxyArgs) {
let file = create_file(PROXIES_SOURCE_FILE_NAME, args.overwrite);
write_proxies_to_file(file, self.original_contract_abi.clone());
pub fn generate_proxy(&self) {
let file = create_file(PROXIES_SOURCE_FILE_NAME);
write_proxy_to_file(file, &self.original_contract_abi);
}
}

fn write_proxies_to_file(mut file: File, abi: ContractAbi) {
fn write_proxy_to_file(mut file: File, abi: &ContractAbi) {
write_header(&mut file);
write_struct_template(&mut file, &abi.name);
write_impl_for_tx_proxy(&mut file, &abi.name);
write_struct_tx_proxy_methods(&mut file, &abi.name);
write_content(&mut file, abi);
write_content(&mut file, abi.clone());
}

0 comments on commit 1869010

Please sign in to comment.