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

10
Cargo.lock generated
View file

@ -366,6 +366,7 @@ dependencies = [
"maplit", "maplit",
"owo-colors 4.0.0", "owo-colors 4.0.0",
"serde_json", "serde_json",
"spdx",
"syntect", "syntect",
"tokio", "tokio",
"validate_package_name", "validate_package_name",
@ -1249,6 +1250,15 @@ version = "1.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
[[package]]
name = "spdx"
version = "0.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47317bbaf63785b53861e1ae2d11b80d6b624211d42cb20efcd210ee6f8a14bc"
dependencies = [
"smallvec",
]
[[package]] [[package]]
name = "strsim" name = "strsim"
version = "0.11.1" version = "0.11.1"

View file

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

View file

@ -84,6 +84,12 @@ pub async fn init() -> Result<()> {
.interact_text()?; .interact_text()?;
let license: String = Input::with_theme(&ColorfulTheme::default()) let license: String = Input::with_theme(&ColorfulTheme::default())
.with_prompt("License") .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()) .default("MIT".into())
.interact_text()?; .interact_text()?;