From 3f61170ce67c899c36ee89f5021499b9b9ec0d4a Mon Sep 17 00:00:00 2001 From: eliasmpw Date: Mon, 21 Aug 2023 18:30:39 +0200 Subject: [PATCH] chore: update minimal version message and selector --- .github/scripts/test_generate.sh | 2 +- increment/cargo-generate.toml | 17 ++++++++------- increment/src/contract.rs | 36 ++++++++++++++++---------------- increment/src/helpers.rs | 6 +++--- increment/src/lib.rs | 2 +- increment/src/msg.rs | 8 +++---- increment/src/state.rs | 2 +- 7 files changed, 38 insertions(+), 35 deletions(-) diff --git a/.github/scripts/test_generate.sh b/.github/scripts/test_generate.sh index 9fc6983..26b7225 100755 --- a/.github/scripts/test_generate.sh +++ b/.github/scripts/test_generate.sh @@ -20,7 +20,7 @@ function test-template() { GIT_BRANCH=$(git -C "$REPO_ROOT" branch --show-current) echo "Generating project from local repository (branch $GIT_BRANCH) ..." - cargo generate --path "$REPO_ROOT" --name "$PROJECT_NAME" -d minimal=false "$TEMPLATE" + cargo generate --path "$REPO_ROOT" --name "$PROJECT_NAME" -d version=full "$TEMPLATE" ( cd "$PROJECT_NAME" diff --git a/increment/cargo-generate.toml b/increment/cargo-generate.toml index 72f4e4f..aef178b 100644 --- a/increment/cargo-generate.toml +++ b/increment/cargo-generate.toml @@ -4,15 +4,18 @@ # The files will be copied 1:1 to the target project. To avoid shipping them completely add them to `.genignore`. exclude = [".circleci/config.yml"] -[placeholders.minimal] -type = "bool" -prompt = """The full template includes some example logic in case you're new to CosmWasm smart contracts. -The minimal template assumes you already know how to write your own logic, and doesn't get in your way. +[placeholders.version] +type = "string" +choices = ["full", "minimal"] +prompt = """This template has 2 versions: -Would you like to generate the minimal template?""" -default = false +- The full template includes example logic in case you're new to CosmWasm smart contracts. +- The minimal template assumes you already know how to write your own logic, includes the bare minimum and doesn't get in your way. -[conditional.'minimal'] +Which version do you want to generate?""" +default = "full" + +[conditional.'version == "minimal"'] ignore = [ "Developing.md", "Importing.md", diff --git a/increment/src/contract.rs b/increment/src/contract.rs index 8df0eea..80e8fcb 100644 --- a/increment/src/contract.rs +++ b/increment/src/contract.rs @@ -1,26 +1,26 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; -use cosmwasm_std::{% raw %}{{% endraw %}{% unless minimal %}to_binary, {% endunless %}Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult}; -{% if minimal %}// {% endif %}use cw2::set_contract_version; +use cosmwasm_std::{% raw %}{{% endraw %}{% unless version == "minimal" %}to_binary, {% endunless %}Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult}; +{% if version == "minimal" %}// {% endif %}use cw2::set_contract_version; use crate::error::ContractError; use crate::msg::{ExecuteMsg, {% unless minimal %}GetCountResponse, {% endunless %}InstantiateMsg, QueryMsg}; -{% unless minimal %}use crate::state::{State, STATE}; +{% unless version == "minimal" %}use crate::state::{State, STATE}; {% endunless %} -{% if minimal %}/* +{% if version == "minimal" %}/* {% endif %}// version info for migration info const CONTRACT_NAME: &str = "crates.io:{{project-name}}"; const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); -{% if minimal %}*/ +{% if version == "minimal" %}*/ {% endif %} #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( - {% if minimal %}_{% endif %}deps: DepsMut, + {% if version == "minimal" %}_{% endif %}deps: DepsMut, _env: Env, - {% if minimal %}_{% endif %}info: MessageInfo, - {% if minimal %}_{% endif %}msg: InstantiateMsg, + {% if version == "minimal" %}_{% endif %}info: MessageInfo, + {% if version == "minimal" %}_{% endif %}msg: InstantiateMsg, ) -> Result { - {% if minimal %}unimplemented!(){% else %}let state = State { + {% if version == "minimal" %}unimplemented!(){% else %}let state = State { count: msg.count, owner: info.sender.clone(), }; @@ -35,16 +35,16 @@ pub fn instantiate( #[cfg_attr(not(feature = "library"), entry_point)] pub fn execute( - {% if minimal %}_{% endif %}deps: DepsMut, + {% if version == "minimal" %}_{% endif %}deps: DepsMut, _env: Env, - {% if minimal %}_{% endif %}info: MessageInfo, - {% if minimal %}_{% endif %}msg: ExecuteMsg, + {% if version == "minimal" %}_{% endif %}info: MessageInfo, + {% if version == "minimal" %}_{% endif %}msg: ExecuteMsg, ) -> Result { - {% if minimal %}unimplemented!(){% else %}match msg { + {% if version == "minimal" %}unimplemented!(){% else %}match msg { ExecuteMsg::Increment {} => execute::increment(deps), ExecuteMsg::Reset { count } => execute::reset(deps, info, count), }{% endif %} -}{% unless minimal %} +}{% unless version == "minimal" %} pub mod execute { use super::*; @@ -71,11 +71,11 @@ pub mod execute { }{% endunless %} #[cfg_attr(not(feature = "library"), entry_point)] -pub fn query({% if minimal %}_{% endif %}deps: Deps, _env: Env, {% if minimal %}_{% endif %}msg: QueryMsg) -> StdResult { - {% if minimal %}unimplemented!(){% else %}match msg { +pub fn query({% if version == "minimal" %}_{% endif %}deps: Deps, _env: Env, {% if version == "minimal" %}_{% endif %}msg: QueryMsg) -> StdResult { + {% if version == "minimal" %}unimplemented!(){% else %}match msg { QueryMsg::GetCount {} => to_binary(&query::count(deps)?), }{% endif %} -}{% unless minimal %} +}{% unless version == "minimal" %} pub mod query { use super::*; @@ -87,7 +87,7 @@ pub mod query { }{% endunless %} #[cfg(test)] -mod tests {% raw %}{{% endraw %}{% unless minimal %} +mod tests {% raw %}{{% endraw %}{% unless version == "minimal" %} use super::*; use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info}; use cosmwasm_std::{coins, from_binary}; diff --git a/increment/src/helpers.rs b/increment/src/helpers.rs index 62a6299..3956aa8 100644 --- a/increment/src/helpers.rs +++ b/increment/src/helpers.rs @@ -1,11 +1,11 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -{% if minimal %}use cosmwasm_std::{to_binary, Addr, CosmosMsg, StdResult, WasmMsg};{% else %}use cosmwasm_std::{ +{% if version == "minimal" %}use cosmwasm_std::{to_binary, Addr, CosmosMsg, StdResult, WasmMsg};{% else %}use cosmwasm_std::{ to_binary, Addr, CosmosMsg, CustomQuery, Querier, QuerierWrapper, StdResult, WasmMsg, WasmQuery, };{% endif %} -{% if minimal %}use crate::msg::ExecuteMsg;{% else %}use crate::msg::{ExecuteMsg, GetCountResponse, QueryMsg};{% endif %} +{% if version == "minimal" %}use crate::msg::ExecuteMsg;{% else %}use crate::msg::{ExecuteMsg, GetCountResponse, QueryMsg};{% endif %} /// CwTemplateContract is a wrapper around Addr that provides a lot of helpers /// for working with this. @@ -25,7 +25,7 @@ impl CwTemplateContract { funds: vec![], } .into()) - }{% unless minimal %} + }{% unless version == "minimal" %} /// Get Count pub fn count(&self, querier: &Q) -> StdResult diff --git a/increment/src/lib.rs b/increment/src/lib.rs index 4c7c0ef..c3814f1 100644 --- a/increment/src/lib.rs +++ b/increment/src/lib.rs @@ -1,7 +1,7 @@ pub mod contract; mod error; pub mod helpers; -{% unless minimal %}pub mod integration_tests; +{% unless version == "minimal" %}pub mod integration_tests; {% endunless %}pub mod msg; pub mod state; diff --git a/increment/src/msg.rs b/increment/src/msg.rs index adf6ef1..d9d87f8 100644 --- a/increment/src/msg.rs +++ b/increment/src/msg.rs @@ -1,24 +1,24 @@ use cosmwasm_schema::{cw_serde, QueryResponses}; #[cw_serde] -pub struct InstantiateMsg {% raw %}{{% endraw %}{% unless minimal %} +pub struct InstantiateMsg {% raw %}{{% endraw %}{% unless version == "minimal" %} pub count: i32, {% endunless %}} #[cw_serde] -pub enum ExecuteMsg {% raw %}{{% endraw %}{% unless minimal %} +pub enum ExecuteMsg {% raw %}{{% endraw %}{% unless version == "minimal" %} Increment {}, Reset { count: i32 }, {% endunless %}} #[cw_serde] #[derive(QueryResponses)] -pub enum QueryMsg {% raw %}{{% endraw %}{% unless minimal %} +pub enum QueryMsg {% raw %}{{% endraw %}{% unless version == "minimal" %} // GetCount returns the current count as a json-encoded number #[returns(GetCountResponse)] GetCount {}, {% endunless %}} -{% unless minimal %} +{% unless version == "minimal" %} // We define a custom struct for each query response #[cw_serde] pub struct GetCountResponse { diff --git a/increment/src/state.rs b/increment/src/state.rs index 50aa373..2c65c4c 100644 --- a/increment/src/state.rs +++ b/increment/src/state.rs @@ -1,4 +1,4 @@ -{% unless minimal %}use schemars::JsonSchema; +{% unless version == "minimal" %}use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use cosmwasm_std::Addr;