Validate licenses in init

This commit is contained in:
SkyfallWasTaken 2024-07-29 14:31:48 +01:00
parent b5c4759c98
commit 6a4a73426a
3 changed files with 17 additions and 0 deletions

View file

@ -24,3 +24,4 @@ maplit = "1.0.2"
serde_json = "1.0.120"
syntect = "5.2.0"
validate_package_name = { path = "../validate_package_name" }
spdx = "0.10.6"

View file

@ -84,6 +84,12 @@ pub async fn init() -> Result<()> {
.interact_text()?;
let license: String = Input::with_theme(&ColorfulTheme::default())
.with_prompt("License")
.validate_with(|input: &String| {
spdx::Expression::parse(input).map_or_else(
|err| Err(format!("license is invalid:\n{}", err.to_string())),
|_| Ok(()),
)
})
.default("MIT".into())
.interact_text()?;