diff --git a/cmd/soroban-cli/src/commands/contract/init.rs b/cmd/soroban-cli/src/commands/contract/init.rs index b5a4ce2c0..487a721a0 100644 --- a/cmd/soroban-cli/src/commands/contract/init.rs +++ b/cmd/soroban-cli/src/commands/contract/init.rs @@ -14,15 +14,12 @@ use clap::{ }; use gix::{clone, create, open, progress, remote}; use rust_embed::RustEmbed; -use serde::Deserialize; 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}; const SOROBAN_EXAMPLES_URL: &str = "https://github.com/stellar/soroban-examples.git"; const GITHUB_URL: &str = "https://github.com"; -const GITHUB_API_URL: &str = - "https://api.github.com/repos/stellar/soroban-examples/git/trees/main?recursive=1"; #[derive(Clone, Debug, ValueEnum, PartialEq)] pub enum FrontendTemplate { @@ -48,14 +45,36 @@ pub struct Cmd { } fn possible_example_values() -> ValueParser { - // If fetching the example contracts from the soroban-examples repo succeeds, return a parser with the example contracts. - if let Ok(examples) = get_valid_examples() { - let parser = PossibleValuesParser::new(examples.iter().map(PossibleValue::new)); - return parser.into(); - } - - // If fetching with example contracts fails, return a string parser that will allow for any value. It will be ignored in `init`. - ValueParser::string() + let parser = PossibleValuesParser::new( + [ + "account", + "alloc", + "atomic_multiswap", + "atomic_swap", + "auth", + "cross_contract", + "custom_types", + "deep_contract_auth", + "deployer", + "errors", + "eth_abi", + "events", + "fuzzing", + "increment", + "liquidity_pool", + "logging", + "mint-lock", + "simple_account", + "single_offer", + "timelock", + "token", + "upgradeable_contract", + "workspace", + ] + .iter() + .map(PossibleValue::new), + ); + parser.into() } fn with_example_help() -> String { @@ -66,42 +85,6 @@ fn with_example_help() -> String { } } -#[derive(Deserialize, Debug)] -struct RepoPath { - path: String, - #[serde(rename = "type")] - type_field: String, -} - -#[derive(Deserialize, Debug)] -struct ReqBody { - tree: Vec, -} - -fn get_valid_examples() -> Result, Error> { - let body: ReqBody = get(GITHUB_API_URL) - .call() - .map_err(|e| { - tracing::warn!("Error fetching example contracts from soroban-examples repo"); - Box::new(e) - })? - .into_json()?; - let mut valid_examples = Vec::new(); - for item in body.tree { - if item.type_field == "blob" - || item.path.starts_with('.') - || item.path.contains('/') - || item.path == "hello_world" - { - continue; - } - - valid_examples.push(item.path); - } - - Ok(valid_examples) -} - #[derive(thiserror::Error, Debug)] pub enum Error { #[error("Io error: {0}")]