Skip to content

Commit ce42cac

Browse files
committed
Merge remote-tracking branch 'origin/master' into ben-auto-bump
2 parents 23b187e + f8eeefc commit ce42cac

File tree

10 files changed

+195
-80
lines changed

10 files changed

+195
-80
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ path = "src/main.rs"
1818

1919
[features]
2020
default = []
21-
gen-readme = ["cargo-readme", "sha1"]
22-
21+
gen-readme = ["cargo-readme","lazy_static","sha1"]
2322

2423
[dependencies]
2524
structopt = "0.3.9"
@@ -42,4 +41,5 @@ git2 = "0.13.10"
4241

4342
# Optional dependencies
4443
cargo-readme = { version="3.2", optional = true }
45-
sha1 = { version="0.6", optional = true }
44+
lazy_static = { version = "1.4", optional = true }
45+
sha1 = { version="0.6", optional = true }

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,4 @@ _You are using the tooling and want to be mentioned here–[create an issue](htt
158158
159159
This Software is released under the [GNU General Public License (GPL) 3.0](https://www.gnu.org/licenses/gpl-3.0.en.html).
160160
161-
This, as any other software, is build on the shoulders of giants. In particular, this uses `cargo` internally and draws heavily on the knowledge established by [cargo publish-all](https://torkleyy.gitlab.io/cargo-publish-all/) and [cargo hack](https://github.com/taiki-e/cargo-hack).
161+
This, as any other software, is build on the shoulders of giants. In particular, this uses `cargo` internally and draws heavily on the knowledge established by [cargo publish-all](https://gitlab.com/torkleyy/cargo-publish-all) and [cargo hack](https://github.com/taiki-e/cargo-hack).

src/cli.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ fn make_pkg_predicate(args: PackageSelectOptions) -> Result<Box<dyn Fn(&Package)
411411
return false;
412412
}
413413
let name = p.name();
414-
if skip.iter().find(|r| r.is_match(&name)).is_some() {
414+
if skip.iter().any(|r| r.is_match(&name)) {
415415
return false;
416416
}
417417
if p.version().is_prerelease() {
@@ -453,7 +453,7 @@ pub fn run(args: Opt) -> Result<(), Box<dyn Error>> {
453453
fs::canonicalize(path)?
454454
};
455455

456-
let maybe_patch = |shouldnt_patch, predicate: &Box<dyn Fn(&Package) -> bool>| {
456+
let maybe_patch = |shouldnt_patch, predicate: &dyn Fn(&Package) -> bool| {
457457
if shouldnt_patch {
458458
return Ok(());
459459
}
@@ -498,15 +498,13 @@ pub fn run(args: Opt) -> Result<(), Box<dyn Error>> {
498498
value,
499499
pkg_opts,
500500
} => {
501-
if name == "name".to_owned() {
501+
if name == "name" {
502502
return Err("To change the name please use the rename command!".into());
503503
}
504504
let predicate = make_pkg_predicate(pkg_opts)?;
505505
let type_value = {
506-
if &value == "true" {
507-
Value::from(true)
508-
} else if &value == "false" {
509-
Value::from(true)
506+
if let Ok(v) = bool::from_str(&value) {
507+
Value::from(v)
510508
} else if let Ok(v) = i64::from_str(&value) {
511509
Value::from(v)
512510
} else {
@@ -735,7 +733,7 @@ pub fn run(args: Opt) -> Result<(), Box<dyn Error>> {
735733
.map_err(|e| format!("Reading workspace {:?} failed: {:}", root_manifest, e))?;
736734
let packages = commands::packages_to_release(&ws, predicate)?;
737735

738-
commands::gen_all_readme(&packages, &ws, readme_mode)
736+
commands::gen_all_readme(packages, &ws, readme_mode)
739737
}
740738
Command::EmDragons {
741739
dry_run,

src/commands/check.rs

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fn run_check(
8282
// package has a workspace we can still build our new crate.
8383
let (src, new_pkg) = {
8484
let id = SourceId::for_path(&dst)?;
85-
let mut src = PathSource::new(&dst, id.clone(), ws.config());
85+
let mut src = PathSource::new(&dst, id, ws.config());
8686
let new_pkg = src.root_package()?;
8787

8888
// inject our local builds
@@ -147,7 +147,7 @@ fn run_check(
147147
Ok(())
148148
}
149149

150-
fn check_dependencies<'a>(package: &'a Package) -> Result<(), String> {
150+
fn check_dependencies(package: &Package) -> Result<(), String> {
151151
let git_deps = package
152152
.dependencies()
153153
.iter()
@@ -163,18 +163,18 @@ fn check_dependencies<'a>(package: &'a Package) -> Result<(), String> {
163163

164164
// ensure metadata is set
165165
// https://doc.rust-lang.org/cargo/reference/publishing.html#before-publishing-a-new-crate
166-
fn check_metadata<'a>(metadata: &'a ManifestMetadata) -> Result<(), String> {
166+
fn check_metadata(metadata: &ManifestMetadata) -> Result<(), String> {
167167
let mut bad_fields = Vec::new();
168-
if metadata.authors.len() == 0 {
168+
if metadata.authors.is_empty() {
169169
bad_fields.push("authors is empty")
170170
}
171-
match metadata.description {
172-
Some(ref s) if s.len() == 0 => bad_fields.push("description is empty"),
171+
match metadata.description.as_deref() {
172+
Some("") => bad_fields.push("description is empty"),
173173
None => bad_fields.push("description is missing"),
174174
_ => {}
175175
}
176-
match metadata.repository {
177-
Some(ref s) if s.len() == 0 => bad_fields.push("repository is empty"),
176+
match metadata.repository.as_deref() {
177+
Some("") => bad_fields.push("repository is empty"),
178178
None => bad_fields.push("repository is missing"),
179179
_ => {}
180180
}
@@ -184,7 +184,7 @@ fn check_metadata<'a>(metadata: &'a ManifestMetadata) -> Result<(), String> {
184184
_ => bad_fields.push("Neither license nor license_file is provided"),
185185
}
186186

187-
if bad_fields.len() == 0 {
187+
if bad_fields.is_empty() {
188188
Ok(())
189189
} else {
190190
Err(bad_fields.join("; "))
@@ -202,8 +202,8 @@ fn check_readme<'a>(_ws: &Workspace<'a>, _pkg: &Package) -> Result<(), String> {
202202
unreachable!()
203203
}
204204

205-
pub fn check<'a, 'r>(
206-
packages: &Vec<Package>,
205+
pub fn check<'a>(
206+
packages: &[Package],
207207
ws: &Workspace<'a>,
208208
build: bool,
209209
check_readme: bool,
@@ -253,12 +253,11 @@ pub fn check<'a, 'r>(
253253
res
254254
});
255255

256-
let errors_count = errors.iter().map(|s| error!("{:#?}", s)).count();
257-
256+
errors.iter().for_each(|s| error!("{:#?}", s));
258257
if errors.len() > 0 {
259258
return Err(format!(
260259
"Soft checkes failed with {} errors (see above)",
261-
errors_count
260+
errors.len()
262261
)
263262
.into());
264263
}
@@ -276,12 +275,11 @@ pub fn check<'a, 'r>(
276275
res
277276
});
278277

279-
let errors_count = errors.iter().map(|s| error!("{:#?}", s)).count();
280-
278+
errors.iter().for_each(|s| error!("{:#?}", s));
281279
if errors.len() > 0 {
282280
return Err(format!(
283281
"{} readme file(s) need to be updated (see above).",
284-
errors_count
282+
errors.len()
285283
)
286284
.into());
287285
}
@@ -298,21 +296,18 @@ pub fn check<'a, 'r>(
298296
.map_err(|e| format!("{:}", e))?;
299297
match package(&pkg_ws, &opts) {
300298
Ok(Some(rw_lock)) => Ok((pkg_ws, rw_lock)),
301-
Ok(None) => Err(format!("Failure packing {:}", pkg.name()).into()),
302-
Err(e) => Err(format!("Failure packing {:}: {}", pkg.name(), e).into()),
299+
Ok(None) => Err(format!("Failure packing {:}", pkg.name())),
300+
Err(e) => Err(format!("Failure packing {:}: {}", pkg.name(), e)),
303301
}
304302
});
305303

306-
let (errors, successes): (Vec<_>, Vec<_>) =
307-
builds.partition(|r: &Result<(Workspace<'_>, FileLock), String>| r.is_err());
304+
let (errors, successes): (Vec<_>, Vec<_>) = builds.partition(Result::is_err);
308305

309-
let errors_count = errors
310-
.iter()
311-
.map(|r| r.as_ref().map_err(|e| error!("{:#?}", e)))
312-
.count();
313-
314-
if errors_count > 0 {
315-
return Err(format!("Packing failed with {} errors (see above)", errors_count).into());
306+
for e in errors.iter().filter_map(|res| res.as_ref().err()) {
307+
error!("{:#?}", e);
308+
}
309+
if errors.len() > 0 {
310+
return Err(format!("Packing failed with {} errors (see above)", errors.len()).into());
316311
};
317312

318313
let build_mode = if build {

0 commit comments

Comments
 (0)