Skip to content

Commit

Permalink
Change spin new tpl name to spin new name -t tpl
Browse files Browse the repository at this point in the history
Signed-off-by: itowlson <ivan.towlson@fermyon.com>
  • Loading branch information
itowlson committed Oct 10, 2023
1 parent b13a23c commit 93dd063
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion crates/e2e-testing/src/spin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn new_app<'a>(
mut args: Vec<&'a str>,
) -> Result<Output> {
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);
}
Expand Down
18 changes: 15 additions & 3 deletions src/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,

/// The name of the new application or component.
#[clap(value_parser = validate_name)]
pub name: Option<String>,

/// 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<String>,

/// Filter templates to select by tags.
#[clap(
long = "tag",
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 93dd063

Please # to comment.