Skip to content

Commit

Permalink
Simplify validate_name
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Mar 24, 2024
1 parent 6c38021 commit 5b537d8
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions src/new_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,9 @@ impl<'a> ProjectGenerator<'a> {
}

fn validate_name(name: &str) -> anyhow::Result<String> {
let cargo_result = cargo_check_name(name);
let pypi_result = pypi_check_name(name);

match (cargo_result, pypi_result) {
(Err(cargo_error), _) => {
let error_message = format!("Invalid Cargo package name: {}", cargo_error);
Err(anyhow::Error::msg(error_message))
}
(_, Err(pypi_error)) => {
let error_message = format!("Invalid PyPi package name: {}", pypi_error);
Err(anyhow::Error::msg(error_message))
}
(Ok(_), Ok(_)) => Ok(name.to_string()),
}
cargo_check_name(name).context("Invalid Cargo package name")?;
pypi_check_name(name).context("Invalid PyPI package name")?;
Ok(name.to_string())
}
/// Options common to `maturin new` and `maturin init`.
#[derive(Debug, clap::Parser)]
Expand Down

0 comments on commit 5b537d8

Please sign in to comment.