Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions crates/cli/src/subcommands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -208,6 +210,19 @@ pub async fn fetch_templates_list() -> anyhow::Result<Vec<TemplateDefinition>> {
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 <id>");
println!("Browse all templates: {}", "https://spacetimedb.com/templates".cyan());

Ok(())
}

pub async fn check_and_prompt_login(config: &mut Config) -> anyhow::Result<bool> {
if config.spacetimedb_token().is_some() {
println!("{}", "You are logged in to SpacetimeDB.".green());
Expand Down Expand Up @@ -1669,6 +1684,13 @@ fn check_for_git() -> bool {

pub async fn exec(mut config: Config, args: &ArgMatches) -> anyhow::Result<PathBuf> {
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();
Expand Down
Loading