Skip to content

Commit

Permalink
Update template CLI for latest changes to entropy-test-cli (#96)
Browse files Browse the repository at this point in the history
* Update template CLI for latest changes to CLI

* Use clap parser

* Taplo
  • Loading branch information
ameba23 authored Dec 3, 2024
1 parent b300dab commit cdb2ac0
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 21 deletions.
9 changes: 6 additions & 3 deletions templates/basic-template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ strip = "debuginfo"
crate-type = ["cdylib", "rlib"]

[dependencies]
entropy-programs-core={ git="https://github.com/entropyxyz/programs.git", tag="v0.10.0" }
schemars = {version = "0.8.16", optional = true}
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] }
entropy-programs-core = { git = "https://github.com/entropyxyz/programs.git", tag = "v0.10.0" }
schemars = { version = "0.8.16", optional = true }
serde = { version = "1.0", default-features = false, features = [
"alloc",
"derive",
] }

# These are used by `cargo component`
[package.metadata.component]
Expand Down
19 changes: 11 additions & 8 deletions templates/basic-template/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ name = "cli"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap ={ version="4.4.6", features=["derive"] }
subxt ={version = "0.35.3", features = ["substrate-compat"]}
colored ="2.0.4"
tokio ={ version="1.16", features=["macros", "rt-multi-thread", "io-util", "process"] }
anyhow ="1.0.82"
clap = { version = "4.5.20", features = ["derive"] }
subxt = { version = "0.35.3", features = ["substrate-compat"] }
colored = "2.0.4"
tokio = { version = "1.16", features = [
"macros",
"rt-multi-thread",
"io-util",
"process",
] }
anyhow = "1.0.82"
dotenv = "0.15.0"
generate-types = { path = "../generate-types" }
project-root = "0.2.2"
entropy-test-cli = { git="https://github.com/entropyxyz/entropy-core.git", branch = "master" }
entropy-test-cli = { git = "https://github.com/entropyxyz/entropy-core.git", branch = "master" }
43 changes: 35 additions & 8 deletions templates/basic-template/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,51 @@
use clap::Parser;
use colored::Colorize;
use entropy_test_cli::{run_command, PROGRAM_VERSION_NUMBER};
use dotenv::dotenv;
use entropy_test_cli::{run_command, Cli, PROGRAM_VERSION_NUMBER};
use generate_types::generate_types;
use project_root::get_project_root;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
dotenv().ok();
let program = format!("{}/target/wasm32-unknown-unknown/release/{{project-name}}.wasm", get_project_root()?.to_string_lossy());
let program = format!(
"{}/target/wasm32-unknown-unknown/release/{{project-name}}.wasm",
get_project_root()?.to_string_lossy()
);
generate_types();
let config_interface = format!("{}/{{project-name}}_serialized_config_type.txt", get_project_root()?.to_string_lossy());
let aux_data_interface = format!("{}/{{project-name}}_serialized_aux_data_type.txt", get_project_root()?.to_string_lossy());
match run_command(Some(program.into()), Some(config_interface.into()), Some(aux_data_interface.into()), Some(PROGRAM_VERSION_NUMBER)).await {
let config_interface = format!(
"{}/{{project-name}}_serialized_config_type.txt",
get_project_root()?.to_string_lossy()
);
let aux_data_interface = format!(
"{}/{{project-name}}_serialized_aux_data_type.txt",
get_project_root()?.to_string_lossy()
);

let cli = Cli::parse();
let json_ouput = cli.json;
match run_command(
cli,
Some(program.into()),
Some(config_interface.into()),
Some(aux_data_interface.into()),
Some(PROGRAM_VERSION_NUMBER),
)
.await
{
Ok(output) => {
println!("Success: {}", output.green());
if json_ouput {
println!("{}", output);
} else {
println!("Success: {}", output.green());
}
Ok(())
}
Err(err) => {
println!("{}", "Failed!".red());
if !json_ouput {
eprintln!("{}", "Failed!".red());
}
Err(err)
}
}
}
}
6 changes: 4 additions & 2 deletions templates/basic-template/generate-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
program = { package= "{{project-name}}", path = "..", default-features = false, features=['std'] }
program = { package = "{{project-name}}", path = "..", default-features = false, features = [
'std',
] }
schemars = "0.8.16"
serde_json = { version = "1.0" }
serde_json = { version = "1.0" }

0 comments on commit cdb2ac0

Please sign in to comment.