From 46cbe05702d46b971b86201156419e137da55bca Mon Sep 17 00:00:00 2001 From: Elizabeth Engelman <4752801+elizabethengelman@users.noreply.github.com> Date: Wed, 6 Mar 2024 11:51:04 -0500 Subject: [PATCH] Removed unused/unnecessary functionality in init.rs --- cmd/soroban-cli/Cargo.toml | 1 + cmd/soroban-cli/build.rs | 16 ++++++++++++++-- cmd/soroban-cli/src/commands/contract/init.rs | 17 ++++------------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/cmd/soroban-cli/Cargo.toml b/cmd/soroban-cli/Cargo.toml index afd0103fa..666b8c456 100644 --- a/cmd/soroban-cli/Cargo.toml +++ b/cmd/soroban-cli/Cargo.toml @@ -116,6 +116,7 @@ openssl = { version = "=0.10.55", features = ["vendored"] } [build-dependencies] crate-git-revision = "0.0.4" serde.workspace = true +thiserror.workspace = true ureq = { version = "2.9.1", features = ["json"] } diff --git a/cmd/soroban-cli/build.rs b/cmd/soroban-cli/build.rs index 8fe6bf4b8..69efe8f2e 100644 --- a/cmd/soroban-cli/build.rs +++ b/cmd/soroban-cli/build.rs @@ -25,8 +25,20 @@ struct ReqBody { tree: Vec, } -fn get_example_contracts() -> Result, ureq::Error> { - let body: ReqBody = ureq::get(GITHUB_API_URL).call()?.into_json()?; +#[derive(thiserror::Error, Debug)] +pub enum Error { + #[error("Failed to complete get request")] + UreqError(#[from] Box), + + #[error("Io error: {0}")] + IoError(#[from] std::io::Error), +} + +fn get_example_contracts() -> Result, Error> { + let body: ReqBody = ureq::get(GITHUB_API_URL) + .call() + .map_err(Box::new)? + .into_json()?; let mut valid_examples = Vec::new(); for item in body.tree { if item.type_field == "blob" diff --git a/cmd/soroban-cli/src/commands/contract/init.rs b/cmd/soroban-cli/src/commands/contract/init.rs index 731af94a3..49cf9b857 100644 --- a/cmd/soroban-cli/src/commands/contract/init.rs +++ b/cmd/soroban-cli/src/commands/contract/init.rs @@ -16,10 +16,12 @@ use gix::{clone, create, open, progress, remote}; use rust_embed::RustEmbed; use serde_json::{from_str, json, Error as JsonError, Value as JsonValue}; use toml_edit::{Document, Formatted, InlineTable, Item, TomlError, Value as TomlValue}; -use ureq::{get, Error as UreqError}; +use ureq::get; const SOROBAN_EXAMPLES_URL: &str = "https://github.com/stellar/soroban-examples.git"; const GITHUB_URL: &str = "https://github.com"; +const WITH_EXAMPLE_LONG_HELP_TEXT: &str = + "An optional flag to specify Soroban example contracts to include. A hello-world contract will be included by default."; #[derive(Clone, Debug, ValueEnum, PartialEq)] pub enum FrontendTemplate { @@ -32,7 +34,7 @@ pub enum FrontendTemplate { pub struct Cmd { pub project_path: String, - #[arg(short, long, num_args = 1.., value_parser=possible_example_values(), long_help=with_example_help())] + #[arg(short, long, num_args = 1.., value_parser=possible_example_values(), long_help=WITH_EXAMPLE_LONG_HELP_TEXT)] pub with_example: Vec, #[arg( @@ -50,14 +52,6 @@ fn possible_example_values() -> ValueParser { parser.into() } -fn with_example_help() -> String { - if check_internet_connection() { - "An optional flag to specify Soroban example contracts to include. A hello-world contract will be included by default.".to_owned() - } else { - "⚠️ Failed to fetch additional example contracts from soroban-examples repo. You can continue with initializing - the default hello_world contract will still be included".to_owned() - } -} - #[derive(thiserror::Error, Debug)] pub enum Error { #[error("Io error: {0}")] @@ -77,9 +71,6 @@ pub enum Error { #[error("Failed to parse toml file: {0}")] TomlParseError(#[from] TomlError), - #[error("Failed to complete get request")] - UreqError(#[from] Box), - #[error("Failed to parse package.json file: {0}")] JsonParseError(#[from] JsonError),