From 1f2d1370fa9a26c8e4bff5b99a7be3eba9c49adf Mon Sep 17 00:00:00 2001 From: Tien Pham Date: Wed, 10 Jun 2026 15:37:02 +0300 Subject: [PATCH] feat(cli): spacetime init --template without arg prints templates list and link to website --- crates/cli/src/subcommands/init.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/crates/cli/src/subcommands/init.rs b/crates/cli/src/subcommands/init.rs index 80eb25e4206..449e34931a2 100644 --- a/crates/cli/src/subcommands/init.rs +++ b/crates/cli/src/subcommands/init.rs @@ -179,6 +179,8 @@ pub fn cli() -> clap::Command { .short('t') .long("template") .value_name("TEMPLATE") + .num_args(0..=1) + .default_missing_value("") .help("Template ID or GitHub repository (owner/repo or URL)"), ) .arg( @@ -208,6 +210,19 @@ pub async fn fetch_templates_list() -> anyhow::Result> { Ok(templates_list.templates) } +async fn print_templates_list() -> anyhow::Result<()> { + let templates = fetch_templates_list().await?; + + println!("{}", "Available templates:".bold()); + for template in &templates { + println!(" {} - {}", template.id, template.description); + } + println!("\nCreate a project: spacetime init --template "); + println!("Browse all templates: {}", "https://spacetimedb.com/templates".cyan()); + + Ok(()) +} + pub async fn check_and_prompt_login(config: &mut Config) -> anyhow::Result { if config.spacetimedb_token().is_some() { println!("{}", "You are logged in to SpacetimeDB.".green()); @@ -1669,6 +1684,13 @@ fn check_for_git() -> bool { pub async fn exec(mut config: Config, args: &ArgMatches) -> anyhow::Result { let options = InitOptions::from_args(args); + + // --template without arg prints templates list and link to website + if options.template.as_deref() == Some("") { + print_templates_list().await?; + return Ok(PathBuf::new()); + } + let is_interactive = !options.non_interactive; let template = options.template.as_ref(); let server_lang = options.lang.as_ref();