Validate package name in init

This commit is contained in:
SkyfallWasTaken 2024-07-29 14:22:27 +01:00
parent bdd34ed8bb
commit b5c4759c98
3 changed files with 24 additions and 18 deletions

34
Cargo.lock generated
View file

@ -368,6 +368,7 @@ dependencies = [
"serde_json",
"syntect",
"tokio",
"validate_package_name",
]
[[package]]
@ -478,9 +479,9 @@ checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
[[package]]
name = "gix-actor"
version = "0.31.4"
version = "0.31.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b8ee65074b2bbb91d9d97c15d172ea75043aefebf9869b5b329149dc76501c"
checksum = "a0e454357e34b833cc3a00b6efbbd3dd4d18b24b9fb0c023876ec2645e8aa3f2"
dependencies = [
"bstr",
"gix-date",
@ -492,9 +493,9 @@ dependencies = [
[[package]]
name = "gix-config"
version = "0.37.0"
version = "0.38.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53fafe42957e11d98e354a66b6bd70aeea00faf2f62dd11164188224a507c840"
checksum = "28f53fd03d1bf09ebcc2c8654f08969439c4556e644ca925f27cf033bc43e658"
dependencies = [
"bstr",
"gix-config-value",
@ -513,9 +514,9 @@ dependencies = [
[[package]]
name = "gix-config-value"
version = "0.14.6"
version = "0.14.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbd06203b1a9b33a78c88252a625031b094d9e1b647260070c25b09910c0a804"
checksum = "b328997d74dd15dc71b2773b162cb4af9a25c424105e4876e6d0686ab41c383e"
dependencies = [
"bitflags 2.6.0",
"bstr",
@ -553,9 +554,9 @@ dependencies = [
[[package]]
name = "gix-fs"
version = "0.11.1"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3338ff92a2164f5209f185ec0cd316f571a72676bb01d27e22f2867ba69f77a"
checksum = "6adf99c27cdf17b1c4d77680c917e0d94d8783d4e1c73d3be0d1d63107163d7a"
dependencies = [
"fastrand",
"gix-features",
@ -564,9 +565,9 @@ dependencies = [
[[package]]
name = "gix-glob"
version = "0.16.3"
version = "0.16.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a29ad0990cf02c48a7aac76ed0dbddeb5a0d070034b83675cc3bbf937eace4"
checksum = "fa7df15afa265cc8abe92813cd354d522f1ac06b29ec6dfa163ad320575cb447"
dependencies = [
"bitflags 2.6.0",
"bstr",
@ -616,9 +617,9 @@ dependencies = [
[[package]]
name = "gix-path"
version = "0.10.8"
version = "0.10.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca987128ffb056d732bd545db5db3d8b103d252fbf083c2567bb0796876619a4"
checksum = "8d23d5bbda31344d8abc8de7c075b3cf26e5873feba7c4a15d916bce67382bd9"
dependencies = [
"bstr",
"gix-trace",
@ -629,12 +630,11 @@ dependencies = [
[[package]]
name = "gix-ref"
version = "0.44.1"
version = "0.45.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3394a2997e5bc6b22ebc1e1a87b41eeefbcfcff3dbfa7c4bd73cb0ac8f1f3e2e"
checksum = "636e96a0a5562715153fee098c217110c33a6f8218f08f4687ff99afde159bb5"
dependencies = [
"gix-actor",
"gix-date",
"gix-features",
"gix-fs",
"gix-hash",
@ -651,9 +651,9 @@ dependencies = [
[[package]]
name = "gix-sec"
version = "0.10.6"
version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fddc27984a643b20dd03e97790555804f98cf07404e0e552c0ad8133266a79a1"
checksum = "1547d26fa5693a7f34f05b4a3b59a90890972922172653bcb891ab3f09f436df"
dependencies = [
"bitflags 2.6.0",
"gix-path",

View file

@ -19,7 +19,8 @@ exitcode = "1.1.2"
env_logger = "0.11.3"
dialoguer = "0.11.0"
camino = "1.1.7"
gix-config = "0.37.0"
gix-config = "0.38.0"
maplit = "1.0.2"
serde_json = "1.0.120"
syntect = "5.2.0"
validate_package_name = { path = "../validate_package_name" }

View file

@ -47,6 +47,11 @@ pub async fn init() -> Result<()> {
// Now, onto the questions!
let package_name: String = Input::with_theme(&ColorfulTheme::default())
.with_prompt("Package name")
.validate_with(
|input: &String| -> Result<(), validate_package_name::Error> {
validate_package_name::validate(input)
},
)
.default(current_dir_name.into())
.interact_text()?;
let version: String = Input::with_theme(&ColorfulTheme::default())