From c2f05f120c454e34b158457abc69c40ff2e5bf72 Mon Sep 17 00:00:00 2001 From: Alin Cruceat Date: Tue, 6 Aug 2024 14:06:49 +0300 Subject: [PATCH 1/5] add author flag to sc-meta template + default --- framework/meta-lib/src/cargo_toml_contents.rs | 30 +++++++++++- framework/meta/src/cli/cli_args_standalone.rs | 5 ++ .../meta/src/cmd/template/contract_creator.rs | 12 +++-- .../src/cmd/template/template_adjuster.rs | 22 +++++---- framework/meta/tests/template_test.rs | 48 ++++++++++++++----- 5 files changed, 88 insertions(+), 29 deletions(-) diff --git a/framework/meta-lib/src/cargo_toml_contents.rs b/framework/meta-lib/src/cargo_toml_contents.rs index 49721f5cec..1ffc984dbf 100644 --- a/framework/meta-lib/src/cargo_toml_contents.rs +++ b/framework/meta-lib/src/cargo_toml_contents.rs @@ -10,6 +10,9 @@ use crate::contract::sc_config::ContractVariantProfile; pub const CARGO_TOML_DEPENDENCIES: &str = "dependencies"; pub const CARGO_TOML_DEV_DEPENDENCIES: &str = "dev-dependencies"; +pub const PACKAGE: &str = "package"; +pub const AUTHORS: &str = "authors"; +const DEFAULT_AUTHOR: &str = "you"; const AUTO_GENERATED: &str = "# Code generated by the multiversx-sc build system. DO NOT EDIT. # ########################################## @@ -69,7 +72,7 @@ impl CargoTomlContents { pub fn package_name(&self) -> String { self.toml_value - .get("package") + .get(PACKAGE) .expect("missing package in Cargo.toml") .get("name") .expect("missing package name in Cargo.toml") @@ -80,7 +83,7 @@ impl CargoTomlContents { pub fn package_edition(&self) -> String { self.toml_value - .get("package") + .get(PACKAGE) .expect("missing package in Cargo.toml") .get("edition") .expect("missing package name in Cargo.toml") @@ -158,6 +161,29 @@ impl CargoTomlContents { self.toml_value.get(CARGO_TOML_DEV_DEPENDENCIES).is_some() } + pub fn change_author(&mut self, authors: PathBuf) -> bool { + let package = self + .toml_value + .get_mut(PACKAGE) + .unwrap_or_else(|| panic!("no dependencies found in crate {}", self.path.display())) + .as_table_mut() + .expect("missing package in Cargo.toml"); + + package.remove(AUTHORS); + + let mut author_as_str = authors + .into_os_string() + .into_string() + .unwrap_or(DEFAULT_AUTHOR.to_string()); + if author_as_str.is_empty() { + author_as_str = DEFAULT_AUTHOR.to_string(); + } + let new_authors = vec![toml::Value::String(author_as_str)]; + package.insert(AUTHORS.to_owned(), toml::Value::Array(new_authors)); + + true + } + pub fn dev_dependencies_mut(&mut self) -> &mut Table { self.toml_value .get_mut(CARGO_TOML_DEV_DEPENDENCIES) diff --git a/framework/meta/src/cli/cli_args_standalone.rs b/framework/meta/src/cli/cli_args_standalone.rs index e66c83deb4..d9d4ca5a4e 100644 --- a/framework/meta/src/cli/cli_args_standalone.rs +++ b/framework/meta/src/cli/cli_args_standalone.rs @@ -265,6 +265,11 @@ pub struct TemplateArgs { /// Will be current directory if not specified. #[arg(long, verbatim_doc_comment)] pub path: Option, + + /// The author of the contract is to receive. + /// If missing, the template author will be considered. + #[arg(long, verbatim_doc_comment)] + pub author: Option, } impl CliArgsToRaw for TemplateArgs { diff --git a/framework/meta/src/cmd/template/contract_creator.rs b/framework/meta/src/cmd/template/contract_creator.rs index 65e45f4d47..cac4d9a7d0 100644 --- a/framework/meta/src/cmd/template/contract_creator.rs +++ b/framework/meta/src/cmd/template/contract_creator.rs @@ -1,3 +1,5 @@ +use std::path::PathBuf; + use convert_case::{Case, Casing}; use crate::{ @@ -20,7 +22,7 @@ pub fn create_contract(args: &TemplateArgs) { let creator = ContractCreator::new(&repo_temp_download, args.template.clone(), target, false); - creator.create_contract(version_tag); + creator.create_contract(version_tag, args.author.clone().unwrap_or_default()); } fn target_from_args(args: &TemplateArgs) -> ContractCreatorTarget { @@ -79,9 +81,9 @@ impl<'a> ContractCreator<'a> { } } - pub fn create_contract(&self, args_tag: FrameworkVersion) { + pub fn create_contract(&self, args_tag: FrameworkVersion, new_authors: PathBuf) { self.copy_template(args_tag.clone()); - self.update_dependencies(args_tag); + self.update_dependencies(args_tag, new_authors); self.rename_template(); } @@ -90,8 +92,8 @@ impl<'a> ContractCreator<'a> { .copy_template(self.target.contract_dir(), args_tag); } - pub fn update_dependencies(&self, args_tag: FrameworkVersion) { - self.adjuster.update_dependencies(args_tag); + pub fn update_dependencies(&self, args_tag: FrameworkVersion, new_authors: PathBuf) { + self.adjuster.update_dependencies(args_tag, new_authors); } pub fn rename_template(&self) { diff --git a/framework/meta/src/cmd/template/template_adjuster.rs b/framework/meta/src/cmd/template/template_adjuster.rs index e1ac5ad827..332106735e 100644 --- a/framework/meta/src/cmd/template/template_adjuster.rs +++ b/framework/meta/src/cmd/template/template_adjuster.rs @@ -1,3 +1,5 @@ +use std::path::PathBuf; + use super::{template_metadata::TemplateMetadata, ContractCreatorTarget}; use crate::{ cmd::upgrade::upgrade_common::{rename_files, replace_in_files}, @@ -22,14 +24,14 @@ pub struct TemplateAdjuster { pub keep_paths: bool, } impl TemplateAdjuster { - pub fn update_dependencies(&self, args_tag: FrameworkVersion) { - self.update_dependencies_root(); - self.update_dependencies_meta(); - self.update_dependencies_wasm(args_tag); - self.update_dependencies_interact(); + pub fn update_dependencies(&self, args_tag: FrameworkVersion, new_authors: PathBuf) { + self.update_cargo_toml_root(new_authors.clone()); + self.update_cargo_toml_meta(); + self.update_cargo_toml_wasm(args_tag); + self.update_cargo_toml_interact(new_authors); } - fn update_dependencies_root(&self) { + fn update_cargo_toml_root(&self, new_authors: PathBuf) { let cargo_toml_path = self.target.contract_dir().join(ROOT_CARGO_TOML); let mut toml = CargoTomlContents::load_from_file(&cargo_toml_path); @@ -43,10 +45,11 @@ impl TemplateAdjuster { toml.add_workspace(&[".", "meta"]); } + toml.change_author(new_authors); toml.save_to_file(&cargo_toml_path); } - fn update_dependencies_meta(&self) { + fn update_cargo_toml_meta(&self) { let cargo_toml_path = self.target.contract_dir().join(META_CARGO_TOML); let mut toml = CargoTomlContents::load_from_file(&cargo_toml_path); @@ -57,7 +60,7 @@ impl TemplateAdjuster { toml.save_to_file(&cargo_toml_path); } - fn update_dependencies_wasm(&self, args_tag: FrameworkVersion) { + fn update_cargo_toml_wasm(&self, args_tag: FrameworkVersion) { if is_template_with_autogenerated_wasm(args_tag) { return; } @@ -72,7 +75,7 @@ impl TemplateAdjuster { toml.save_to_file(&cargo_toml_path); } - fn update_dependencies_interact(&self) { + fn update_cargo_toml_interact(&self, new_authors: PathBuf) { if !self.metadata.has_interactor { return; } @@ -84,6 +87,7 @@ impl TemplateAdjuster { remove_paths_from_deps(&mut toml, &[&self.metadata.name]); } + toml.change_author(new_authors); toml.save_to_file(&cargo_toml_path); } diff --git a/framework/meta/tests/template_test.rs b/framework/meta/tests/template_test.rs index 4b0fc0bc23..64f86a7751 100644 --- a/framework/meta/tests/template_test.rs +++ b/framework/meta/tests/template_test.rs @@ -1,4 +1,4 @@ -use std::{fs, process::Command}; +use std::{fs, path::PathBuf, process::Command}; use convert_case::{Case, Casing}; use multiversx_sc_meta::{ @@ -32,7 +32,12 @@ fn test_template_list() { #[test] #[cfg_attr(not(feature = "template-test-current"), ignore)] fn template_current_adder() { - template_test_current("adder", "examples", "new-adder"); + template_test_current( + "adder", + "examples", + "new-adder", + "Alin Cruceat ", + ); cargo_check_interactor("examples", "new-adder"); } @@ -40,19 +45,19 @@ fn template_current_adder() { #[test] #[cfg_attr(not(feature = "template-test-current"), ignore)] fn template_current_crypto_zombies() { - template_test_current("crypto-zombies", "examples", "new-crypto-zombies"); + template_test_current("crypto-zombies", "examples", "new-crypto-zombies", ""); } #[test] #[cfg_attr(not(feature = "template-test-current"), ignore)] fn template_current_empty() { - template_test_current("empty", "examples", "new-empty"); + template_test_current("empty", "examples", "new-empty", ""); } #[test] #[cfg_attr(not(feature = "template-test-current"), ignore)] fn template_current_ping_pong_egld() { - template_test_current("ping-pong-egld", "examples", "new-ping-pong-egld"); + template_test_current("ping-pong-egld", "examples", "new-ping-pong-egld", ""); } #[test] @@ -63,13 +68,13 @@ fn test_correct_naming() { "my-new-42-correct-empty" ); - template_test_current("empty", "examples", "my1New2_3-correct_Empty"); + template_test_current("empty", "examples", "my1New2_3-correct_Empty", ""); } /// Recreates the folder structure in `contracts`, on the same level. /// This way, the relative paths are still valid in this case, /// and we can test the templates with the framework version of the current branch. -fn template_test_current(template_name: &str, sub_path: &str, new_name: &str) { +fn template_test_current(template_name: &str, sub_path: &str, new_name: &str, new_author: &str) { let workspace_path = find_current_workspace().unwrap(); let target = ContractCreatorTarget { target_path: workspace_path.join(TEMPLATE_TEMP_DIR_NAME).join(sub_path), @@ -80,13 +85,19 @@ fn template_test_current(template_name: &str, sub_path: &str, new_name: &str) { prepare_target_dir(&target); + let author; + if new_author.is_empty() { + author = PathBuf::new(); + } else { + author = PathBuf::from(new_author); + } ContractCreator::new( &repo_source, template_name.to_string(), target.clone(), true, ) - .create_contract(LAST_TEMPLATE_VERSION); + .create_contract(LAST_TEMPLATE_VERSION, author); if BUILD_CONTRACTS { build_contract(&target); @@ -97,7 +108,11 @@ fn template_test_current(template_name: &str, sub_path: &str, new_name: &str) { #[test] #[cfg_attr(not(feature = "template-test-released"), ignore)] fn template_released_adder() { - template_test_released("adder", "released-adder"); + template_test_released( + "adder", + "released-adder", + "Alin Cruceat ", + ); cargo_check_interactor("", "released-adder"); } @@ -105,13 +120,13 @@ fn template_released_adder() { #[test] #[cfg_attr(not(feature = "template-test-released"), ignore)] fn template_released_crypto_zombies() { - template_test_released("crypto-zombies", "released-crypto-zombies"); + template_test_released("crypto-zombies", "released-crypto-zombies", ""); } #[test] #[cfg_attr(not(feature = "template-test-released"), ignore)] fn template_released_empty() { - template_test_released("empty", "released-empty"); + template_test_released("empty", "released-empty", ""); } /// These tests fully replicate the templating process. They @@ -119,7 +134,7 @@ fn template_released_empty() { /// - create proper contracts, /// - build the newly created contracts (to wasm) /// - run all tests (including Go scenarios) on them. -fn template_test_released(template_name: &str, new_name: &str) { +fn template_test_released(template_name: &str, new_name: &str, new_author: &str) { let workspace_path = find_current_workspace().unwrap(); let target = ContractCreatorTarget { target_path: workspace_path.join(TEMPLATE_TEMP_DIR_NAME), @@ -137,13 +152,20 @@ fn template_test_released(template_name: &str, new_name: &str) { prepare_target_dir(&target); + let author; + if new_author.is_empty() { + author = PathBuf::new(); + } else { + author = PathBuf::from(new_author); + } + ContractCreator::new( &repo_source, template_name.to_string(), target.clone(), false, ) - .create_contract(LAST_TEMPLATE_VERSION); + .create_contract(LAST_TEMPLATE_VERSION, author); if BUILD_CONTRACTS { build_contract(&target); From 5ffd9e4d41bc77357d7a2c44541195c59696b417 Mon Sep 17 00:00:00 2001 From: Alin Cruceat Date: Tue, 6 Aug 2024 14:12:11 +0300 Subject: [PATCH 2/5] clippy --- framework/meta/tests/template_test.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/framework/meta/tests/template_test.rs b/framework/meta/tests/template_test.rs index 64f86a7751..1667225699 100644 --- a/framework/meta/tests/template_test.rs +++ b/framework/meta/tests/template_test.rs @@ -85,12 +85,12 @@ fn template_test_current(template_name: &str, sub_path: &str, new_name: &str, ne prepare_target_dir(&target); - let author; - if new_author.is_empty() { - author = PathBuf::new(); + let author = if new_author.is_empty() { + PathBuf::new() } else { - author = PathBuf::from(new_author); - } + PathBuf::from(new_author) + }; + ContractCreator::new( &repo_source, template_name.to_string(), @@ -152,12 +152,11 @@ fn template_test_released(template_name: &str, new_name: &str, new_author: &str) prepare_target_dir(&target); - let author; - if new_author.is_empty() { - author = PathBuf::new(); + let author = if new_author.is_empty() { + PathBuf::new() } else { - author = PathBuf::from(new_author); - } + PathBuf::from(new_author) + }; ContractCreator::new( &repo_source, From c6d6e0260ad32290f4c5b7ffa379e1a14a31e1de Mon Sep 17 00:00:00 2001 From: Alin Cruceat Date: Tue, 6 Aug 2024 15:08:18 +0300 Subject: [PATCH 3/5] fix after review --- framework/meta-lib/src/cargo_toml_contents.rs | 16 ++++------- framework/meta/src/cli/cli_args_standalone.rs | 4 +-- .../meta/src/cmd/template/contract_creator.rs | 20 +++++++++----- .../src/cmd/template/template_adjuster.rs | 27 +++++++++++++------ framework/meta/tests/template_test.rs | 14 +++++----- 5 files changed, 48 insertions(+), 33 deletions(-) diff --git a/framework/meta-lib/src/cargo_toml_contents.rs b/framework/meta-lib/src/cargo_toml_contents.rs index 1ffc984dbf..ac6f851ba3 100644 --- a/framework/meta-lib/src/cargo_toml_contents.rs +++ b/framework/meta-lib/src/cargo_toml_contents.rs @@ -12,7 +12,6 @@ pub const CARGO_TOML_DEPENDENCIES: &str = "dependencies"; pub const CARGO_TOML_DEV_DEPENDENCIES: &str = "dev-dependencies"; pub const PACKAGE: &str = "package"; pub const AUTHORS: &str = "authors"; -const DEFAULT_AUTHOR: &str = "you"; const AUTO_GENERATED: &str = "# Code generated by the multiversx-sc build system. DO NOT EDIT. # ########################################## @@ -161,7 +160,7 @@ impl CargoTomlContents { self.toml_value.get(CARGO_TOML_DEV_DEPENDENCIES).is_some() } - pub fn change_author(&mut self, authors: PathBuf) -> bool { + pub fn change_author(&mut self, authors: String) -> bool { let package = self .toml_value .get_mut(PACKAGE) @@ -171,15 +170,10 @@ impl CargoTomlContents { package.remove(AUTHORS); - let mut author_as_str = authors - .into_os_string() - .into_string() - .unwrap_or(DEFAULT_AUTHOR.to_string()); - if author_as_str.is_empty() { - author_as_str = DEFAULT_AUTHOR.to_string(); - } - let new_authors = vec![toml::Value::String(author_as_str)]; - package.insert(AUTHORS.to_owned(), toml::Value::Array(new_authors)); + package.insert( + AUTHORS.to_owned(), + toml::Value::Array(vec![toml::Value::String(authors)]), + ); true } diff --git a/framework/meta/src/cli/cli_args_standalone.rs b/framework/meta/src/cli/cli_args_standalone.rs index d9d4ca5a4e..cda40bb307 100644 --- a/framework/meta/src/cli/cli_args_standalone.rs +++ b/framework/meta/src/cli/cli_args_standalone.rs @@ -266,8 +266,8 @@ pub struct TemplateArgs { #[arg(long, verbatim_doc_comment)] pub path: Option, - /// The author of the contract is to receive. - /// If missing, the template author will be considered. + /// The author of the contract. + /// If missing, the default author will be considered. #[arg(long, verbatim_doc_comment)] pub author: Option, } diff --git a/framework/meta/src/cmd/template/contract_creator.rs b/framework/meta/src/cmd/template/contract_creator.rs index cac4d9a7d0..6d25f00f2e 100644 --- a/framework/meta/src/cmd/template/contract_creator.rs +++ b/framework/meta/src/cmd/template/contract_creator.rs @@ -20,9 +20,15 @@ pub fn create_contract(args: &TemplateArgs) { let repo_temp_download = RepoSource::download_from_github(version, std::env::temp_dir()); let target = target_from_args(args); - let creator = ContractCreator::new(&repo_temp_download, args.template.clone(), target, false); + let creator = ContractCreator::new( + &repo_temp_download, + args.template.clone(), + target, + false, + args.author.clone(), + ); - creator.create_contract(version_tag, args.author.clone().unwrap_or_default()); + creator.create_contract(version_tag); } fn target_from_args(args: &TemplateArgs) -> ContractCreatorTarget { @@ -61,6 +67,7 @@ impl<'a> ContractCreator<'a> { template_name: String, target: ContractCreatorTarget, keep_paths: bool, + new_author: Option, ) -> Self { let template_sources = template_sources(repo_source); let template_source = template_sources @@ -77,13 +84,14 @@ impl<'a> ContractCreator<'a> { metadata, target, keep_paths, + new_author, }, } } - pub fn create_contract(&self, args_tag: FrameworkVersion, new_authors: PathBuf) { + pub fn create_contract(&self, args_tag: FrameworkVersion) { self.copy_template(args_tag.clone()); - self.update_dependencies(args_tag, new_authors); + self.update_dependencies(args_tag); self.rename_template(); } @@ -92,8 +100,8 @@ impl<'a> ContractCreator<'a> { .copy_template(self.target.contract_dir(), args_tag); } - pub fn update_dependencies(&self, args_tag: FrameworkVersion, new_authors: PathBuf) { - self.adjuster.update_dependencies(args_tag, new_authors); + pub fn update_dependencies(&self, args_tag: FrameworkVersion) { + self.adjuster.update_cargo_toml_files(args_tag); } pub fn rename_template(&self) { diff --git a/framework/meta/src/cmd/template/template_adjuster.rs b/framework/meta/src/cmd/template/template_adjuster.rs index 332106735e..98bb3f4575 100644 --- a/framework/meta/src/cmd/template/template_adjuster.rs +++ b/framework/meta/src/cmd/template/template_adjuster.rs @@ -17,21 +17,33 @@ const ROOT_CARGO_TOML: &str = "./Cargo.toml"; const META_CARGO_TOML: &str = "./meta/Cargo.toml"; const WASM_CARGO_TOML: &str = "./wasm/Cargo.toml"; const INTERACT_CARGO_TOML: &str = "./interact/Cargo.toml"; +const DEFAULT_AUTHOR: &str = "you"; pub struct TemplateAdjuster { pub metadata: TemplateMetadata, pub target: ContractCreatorTarget, pub keep_paths: bool, + pub new_author: Option, } impl TemplateAdjuster { - pub fn update_dependencies(&self, args_tag: FrameworkVersion, new_authors: PathBuf) { - self.update_cargo_toml_root(new_authors.clone()); + pub fn update_cargo_toml_files(&self, args_tag: FrameworkVersion) { + let author_as_str = if self.new_author.is_none() { + DEFAULT_AUTHOR.to_string() + } else { + self.new_author + .clone() + .unwrap() + .into_os_string() + .into_string() + .unwrap_or(DEFAULT_AUTHOR.to_string()) + }; + self.update_cargo_toml_root(author_as_str.clone()); self.update_cargo_toml_meta(); self.update_cargo_toml_wasm(args_tag); - self.update_cargo_toml_interact(new_authors); + self.update_cargo_toml_interact(author_as_str); } - fn update_cargo_toml_root(&self, new_authors: PathBuf) { + fn update_cargo_toml_root(&self, author: String) { let cargo_toml_path = self.target.contract_dir().join(ROOT_CARGO_TOML); let mut toml = CargoTomlContents::load_from_file(&cargo_toml_path); @@ -44,8 +56,7 @@ impl TemplateAdjuster { } else { toml.add_workspace(&[".", "meta"]); } - - toml.change_author(new_authors); + toml.change_author(author); toml.save_to_file(&cargo_toml_path); } @@ -75,7 +86,7 @@ impl TemplateAdjuster { toml.save_to_file(&cargo_toml_path); } - fn update_cargo_toml_interact(&self, new_authors: PathBuf) { + fn update_cargo_toml_interact(&self, author: String) { if !self.metadata.has_interactor { return; } @@ -87,7 +98,7 @@ impl TemplateAdjuster { remove_paths_from_deps(&mut toml, &[&self.metadata.name]); } - toml.change_author(new_authors); + toml.change_author(author); toml.save_to_file(&cargo_toml_path); } diff --git a/framework/meta/tests/template_test.rs b/framework/meta/tests/template_test.rs index 1667225699..7898f88fc0 100644 --- a/framework/meta/tests/template_test.rs +++ b/framework/meta/tests/template_test.rs @@ -86,9 +86,9 @@ fn template_test_current(template_name: &str, sub_path: &str, new_name: &str, ne prepare_target_dir(&target); let author = if new_author.is_empty() { - PathBuf::new() + None } else { - PathBuf::from(new_author) + Some(PathBuf::from(new_author)) }; ContractCreator::new( @@ -96,8 +96,9 @@ fn template_test_current(template_name: &str, sub_path: &str, new_name: &str, ne template_name.to_string(), target.clone(), true, + author, ) - .create_contract(LAST_TEMPLATE_VERSION, author); + .create_contract(LAST_TEMPLATE_VERSION); if BUILD_CONTRACTS { build_contract(&target); @@ -153,9 +154,9 @@ fn template_test_released(template_name: &str, new_name: &str, new_author: &str) prepare_target_dir(&target); let author = if new_author.is_empty() { - PathBuf::new() + None } else { - PathBuf::from(new_author) + Some(PathBuf::from(new_author)) }; ContractCreator::new( @@ -163,8 +164,9 @@ fn template_test_released(template_name: &str, new_name: &str, new_author: &str) template_name.to_string(), target.clone(), false, + author, ) - .create_contract(LAST_TEMPLATE_VERSION, author); + .create_contract(LAST_TEMPLATE_VERSION); if BUILD_CONTRACTS { build_contract(&target); From bf4204c475edcabb645517397ec2d9ab1a8cbfbd Mon Sep 17 00:00:00 2001 From: Alin Cruceat Date: Tue, 6 Aug 2024 17:16:34 +0300 Subject: [PATCH 4/5] authos as string, not PathBuf --- framework/meta/src/cli/cli_args_standalone.rs | 2 +- framework/meta/src/cmd/template/contract_creator.rs | 4 +--- framework/meta/src/cmd/template/template_adjuster.rs | 9 ++------- framework/meta/tests/template_test.rs | 6 +++--- 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/framework/meta/src/cli/cli_args_standalone.rs b/framework/meta/src/cli/cli_args_standalone.rs index cda40bb307..335afe41ea 100644 --- a/framework/meta/src/cli/cli_args_standalone.rs +++ b/framework/meta/src/cli/cli_args_standalone.rs @@ -269,7 +269,7 @@ pub struct TemplateArgs { /// The author of the contract. /// If missing, the default author will be considered. #[arg(long, verbatim_doc_comment)] - pub author: Option, + pub author: Option, } impl CliArgsToRaw for TemplateArgs { diff --git a/framework/meta/src/cmd/template/contract_creator.rs b/framework/meta/src/cmd/template/contract_creator.rs index 6d25f00f2e..8483f3c8f8 100644 --- a/framework/meta/src/cmd/template/contract_creator.rs +++ b/framework/meta/src/cmd/template/contract_creator.rs @@ -1,5 +1,3 @@ -use std::path::PathBuf; - use convert_case::{Case, Casing}; use crate::{ @@ -67,7 +65,7 @@ impl<'a> ContractCreator<'a> { template_name: String, target: ContractCreatorTarget, keep_paths: bool, - new_author: Option, + new_author: Option, ) -> Self { let template_sources = template_sources(repo_source); let template_source = template_sources diff --git a/framework/meta/src/cmd/template/template_adjuster.rs b/framework/meta/src/cmd/template/template_adjuster.rs index 98bb3f4575..161b80ee5f 100644 --- a/framework/meta/src/cmd/template/template_adjuster.rs +++ b/framework/meta/src/cmd/template/template_adjuster.rs @@ -1,5 +1,3 @@ -use std::path::PathBuf; - use super::{template_metadata::TemplateMetadata, ContractCreatorTarget}; use crate::{ cmd::upgrade::upgrade_common::{rename_files, replace_in_files}, @@ -23,7 +21,7 @@ pub struct TemplateAdjuster { pub metadata: TemplateMetadata, pub target: ContractCreatorTarget, pub keep_paths: bool, - pub new_author: Option, + pub new_author: Option, } impl TemplateAdjuster { pub fn update_cargo_toml_files(&self, args_tag: FrameworkVersion) { @@ -32,10 +30,7 @@ impl TemplateAdjuster { } else { self.new_author .clone() - .unwrap() - .into_os_string() - .into_string() - .unwrap_or(DEFAULT_AUTHOR.to_string()) + .unwrap_or_else(|| DEFAULT_AUTHOR.to_string()) }; self.update_cargo_toml_root(author_as_str.clone()); self.update_cargo_toml_meta(); diff --git a/framework/meta/tests/template_test.rs b/framework/meta/tests/template_test.rs index 7898f88fc0..764aae6f87 100644 --- a/framework/meta/tests/template_test.rs +++ b/framework/meta/tests/template_test.rs @@ -1,4 +1,4 @@ -use std::{fs, path::PathBuf, process::Command}; +use std::{fs, process::Command}; use convert_case::{Case, Casing}; use multiversx_sc_meta::{ @@ -88,7 +88,7 @@ fn template_test_current(template_name: &str, sub_path: &str, new_name: &str, ne let author = if new_author.is_empty() { None } else { - Some(PathBuf::from(new_author)) + Some(new_author.to_string()) }; ContractCreator::new( @@ -156,7 +156,7 @@ fn template_test_released(template_name: &str, new_name: &str, new_author: &str) let author = if new_author.is_empty() { None } else { - Some(PathBuf::from(new_author)) + Some(new_author.to_string()) }; ContractCreator::new( From 36a0918d77b2874a91054fae049c7545995c52fc Mon Sep 17 00:00:00 2001 From: Alin Cruceat Date: Tue, 6 Aug 2024 17:21:34 +0300 Subject: [PATCH 5/5] minor fix --- framework/meta/src/cmd/template/template_adjuster.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/framework/meta/src/cmd/template/template_adjuster.rs b/framework/meta/src/cmd/template/template_adjuster.rs index 161b80ee5f..2e628a9266 100644 --- a/framework/meta/src/cmd/template/template_adjuster.rs +++ b/framework/meta/src/cmd/template/template_adjuster.rs @@ -25,13 +25,10 @@ pub struct TemplateAdjuster { } impl TemplateAdjuster { pub fn update_cargo_toml_files(&self, args_tag: FrameworkVersion) { - let author_as_str = if self.new_author.is_none() { - DEFAULT_AUTHOR.to_string() - } else { - self.new_author - .clone() - .unwrap_or_else(|| DEFAULT_AUTHOR.to_string()) - }; + let author_as_str = self + .new_author + .clone() + .unwrap_or_else(|| DEFAULT_AUTHOR.to_string()); self.update_cargo_toml_root(author_as_str.clone()); self.update_cargo_toml_meta(); self.update_cargo_toml_wasm(args_tag);