Skip to content

Commit 695b978

Browse files
spacetime init --template without arg prints template list and link to website (#5264)
# Description of Changes - spacetime init --template without arg prints templates list and link to website # Screenshot <img width="696" height="392" alt="screenshot" src="https://github.com/user-attachments/assets/98e87537-554b-411b-96ab-3ceb9a6a9d45" /> <!-- Please describe your change, mention any related tickets, and so on here. --> # API and ABI breaking changes <!-- If this is an API or ABI breaking change, please apply the corresponding GitHub label. --> # Expected complexity level and risk 1 <!-- How complicated do you think these changes are? Grade on a scale from 1 to 5, where 1 is a trivial change, and 5 is a deep-reaching and complex change. This complexity rating applies not only to the complexity apparent in the diff, but also to its interactions with existing and future code. If you answered more than a 2, explain what is complex about the PR, and what other components it interacts with in potentially concerning ways. --> # Testing <!-- Describe any testing you've done, and any testing you'd like your reviewers to do, so that you're confident that all the changes work as expected! --> - [x] I tested the changes
1 parent 3ec168d commit 695b978

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

crates/cli/src/subcommands/init.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ pub fn cli() -> clap::Command {
179179
.short('t')
180180
.long("template")
181181
.value_name("TEMPLATE")
182+
.num_args(0..=1)
183+
.default_missing_value("")
182184
.help("Template ID or GitHub repository (owner/repo or URL)"),
183185
)
184186
.arg(
@@ -208,6 +210,19 @@ pub async fn fetch_templates_list() -> anyhow::Result<Vec<TemplateDefinition>> {
208210
Ok(templates_list.templates)
209211
}
210212

213+
async fn print_templates_list() -> anyhow::Result<()> {
214+
let templates = fetch_templates_list().await?;
215+
216+
println!("{}", "Available templates:".bold());
217+
for template in &templates {
218+
println!(" {} - {}", template.id, template.description);
219+
}
220+
println!("\nCreate a project: spacetime init --template <id>");
221+
println!("Browse all templates: {}", "https://spacetimedb.com/templates".cyan());
222+
223+
Ok(())
224+
}
225+
211226
pub async fn check_and_prompt_login(config: &mut Config) -> anyhow::Result<bool> {
212227
if config.spacetimedb_token().is_some() {
213228
println!("{}", "You are logged in to SpacetimeDB.".green());
@@ -1676,6 +1691,13 @@ fn check_for_git() -> bool {
16761691

16771692
pub async fn exec(mut config: Config, args: &ArgMatches) -> anyhow::Result<PathBuf> {
16781693
let options = InitOptions::from_args(args);
1694+
1695+
// --template without arg prints templates list and link to website
1696+
if options.template.as_deref() == Some("") {
1697+
print_templates_list().await?;
1698+
return Ok(PathBuf::new());
1699+
}
1700+
16791701
let is_interactive = !options.non_interactive;
16801702
let template = options.template.as_ref();
16811703
let server_lang = options.lang.as_ref();

0 commit comments

Comments
 (0)