Skip to content
Merged
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
20 changes: 19 additions & 1 deletion src/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,16 @@ impl TemplateNewCommandCore {
}

let name = match &name {
Some(name) => name.to_owned(),
Some(name) => {
if is_kebabbable(name) {
name.to_owned()
} else {
eprintln!(
"Name must be kebab-cased, and each segment must begin with a letter."
);
prompt_name(&variant).await?
}
}
None => prompt_name(&variant).await?,
};

Expand Down Expand Up @@ -398,6 +407,10 @@ fn infer_target_env_from_file(
}
}

fn is_kebabbable(name: &str) -> bool {
spin_manifest::schema::v2::KebabId::try_from(name.to_string()).is_ok()
}

#[derive(Clone, Debug)]
pub struct ParameterValue {
pub name: String,
Expand Down Expand Up @@ -520,6 +533,11 @@ async fn prompt_name(variant: &TemplateVariantInfo) -> anyhow::Result<String> {
if result.trim().is_empty() {
prompt = format!("Name is required. Try another {noun} name (or Crl+C to exit)");
continue;
} else if !is_kebabbable(&result) {
prompt = format!(
"Name must be kebab-cased, and each segment must start with a letter. Try another {noun} name (or Crl+C to exit)"
);
continue;
} else {
return Ok(result);
}
Expand Down
Loading