Skip to content

Commit

Permalink
Removed unused/unnecessary functionality in init.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethengelman committed Mar 6, 2024
1 parent 939c217 commit 46cbe05
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
1 change: 1 addition & 0 deletions cmd/soroban-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }


Expand Down
16 changes: 14 additions & 2 deletions cmd/soroban-cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,20 @@ struct ReqBody {
tree: Vec<RepoPath>,
}

fn get_example_contracts() -> Result<Vec<String>, 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<ureq::Error>),

#[error("Io error: {0}")]
IoError(#[from] std::io::Error),
}

fn get_example_contracts() -> Result<Vec<String>, 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"
Expand Down
17 changes: 4 additions & 13 deletions cmd/soroban-cli/src/commands/contract/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<String>,

#[arg(
Expand All @@ -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}")]
Expand All @@ -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<UreqError>),

#[error("Failed to parse package.json file: {0}")]
JsonParseError(#[from] JsonError),

Expand Down

0 comments on commit 46cbe05

Please sign in to comment.