From 93dd063c74ea33946737c13d2ebb0c41d85941ae Mon Sep 17 00:00:00 2001 From: itowlson Date: Wed, 11 Oct 2023 10:30:39 +1300 Subject: [PATCH] Change `spin new tpl name` to `spin new name -t tpl` Signed-off-by: itowlson --- crates/e2e-testing/src/spin.rs | 2 +- src/commands/new.rs | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/crates/e2e-testing/src/spin.rs b/crates/e2e-testing/src/spin.rs index 4772f65673..ee5e929753 100644 --- a/crates/e2e-testing/src/spin.rs +++ b/crates/e2e-testing/src/spin.rs @@ -30,7 +30,7 @@ pub fn new_app<'a>( mut args: Vec<&'a str>, ) -> Result { let basedir = utils::testcases_base_dir(); - let mut cmd = vec!["spin", "new", template_name, app_name, "--accept-defaults"]; + let mut cmd = vec!["spin", "new", app_name, "-t", template_name, "--accept-defaults"]; if !args.is_empty() { cmd.append(&mut args); } diff --git a/src/commands/new.rs b/src/commands/new.rs index 1d058a5ed8..f92434a2ed 100644 --- a/src/commands/new.rs +++ b/src/commands/new.rs @@ -17,13 +17,14 @@ use crate::opts::{APP_MANIFEST_FILE_OPT, DEFAULT_MANIFEST_FILE}; /// Scaffold a new application based on a template. #[derive(Parser, Debug)] pub struct TemplateNewCommandCore { - /// The template from which to create the new application or component. Run `spin templates list` to see available options. - pub template_id: Option, - /// The name of the new application or component. #[clap(value_parser = validate_name)] pub name: Option, + /// The template from which to create the new application or component. Run `spin templates list` to see available options. + #[clap(short = 't', long = "template")] + pub template_id: Option, + /// Filter templates to select by tags. #[clap( long = "tag", @@ -113,6 +114,17 @@ impl TemplateNewCommandCore { let template_manager = TemplateManager::try_default() .context("Failed to construct template directory path")?; + // If a user types `spin new http-rust` etc. then it's *probably* Spin 1.x muscle memory; + // try to be helpful without getting in the way. + if let Some(name) = &self.name { + if self.template_id.is_none() && matches!(template_manager.get(name), Ok(Some(_))) { + terminal::einfo!( + "This will create an app called {name}.", + "If you meant to use the {name} template, write '-t {name}'." + ) + } + } + let template = match &self.template_id { Some(template_id) => match template_manager .get(template_id)