Skip to content

Commit 1aefac3

Browse files
committed
models::version: Extract validate_license_expr() function
1 parent ef0b0aa commit 1aefac3

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/models/version.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,7 @@ impl NewVersion {
177177

178178
fn validate_license(&mut self, license_file: Option<&str>) -> AppResult<()> {
179179
if let Some(ref license) = self.license {
180-
for part in license.split('/') {
181-
license_exprs::validate_license_expr(part).map_err(|e| {
182-
cargo_err(&format_args!(
183-
"{}; see http://opensource.org/licenses \
184-
for options, and http://spdx.org/licenses/ \
185-
for their identifiers",
186-
e
187-
))
188-
})?;
189-
}
180+
validate_license_expr(license)?;
190181
} else if license_file.is_some() {
191182
// If no license is given, but a license file is given, flag this
192183
// crate as having a nonstandard license. Note that we don't
@@ -197,6 +188,16 @@ impl NewVersion {
197188
}
198189
}
199190

191+
fn validate_license_expr(s: &str) -> AppResult<()> {
192+
for part in s.split('/') {
193+
license_exprs::validate_license_expr(part).map_err(|e| {
194+
cargo_err(&format_args!("{}; see http://opensource.org/licenses for options, and http://spdx.org/licenses/ for their identifiers", e))
195+
})?;
196+
}
197+
198+
Ok(())
199+
}
200+
200201
#[cfg(test)]
201202
mod tests {
202203
use super::TopVersions;

0 commit comments

Comments
 (0)