Skip to content

Commit 6f81364

Browse files
committed
refactor(publish): extract "no publishable found" error
1 parent 2421496 commit 6f81364

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/cargo/ops/registry/publish.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
9393
.filter(|(m, _)| specs.iter().any(|spec| spec.matches(m.package_id())))
9494
.collect();
9595

96+
let (unpublishable, pkgs): (Vec<_>, Vec<_>) = pkgs
97+
.into_iter()
98+
.partition(|(pkg, _)| pkg.publish() == &Some(vec![]));
99+
if !unpublishable.is_empty() {
100+
bail!(
101+
"{} cannot be published.\n\
102+
`package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish.",
103+
unpublishable
104+
.iter()
105+
.map(|(pkg, _)| format!("`{}`", pkg.name()))
106+
.join(", "),
107+
);
108+
}
109+
96110
let just_pkgs: Vec<_> = pkgs.iter().map(|p| p.0).collect();
97111
let reg_or_index = match opts.reg_or_index.clone() {
98112
Some(r) => {
@@ -705,19 +719,6 @@ fn package_list(pkgs: impl IntoIterator<Item = PackageId>, final_sep: &str) -> S
705719
}
706720

707721
fn validate_registry(pkgs: &[&Package], reg_or_index: Option<&RegistryOrIndex>) -> CargoResult<()> {
708-
let unpublishable = pkgs
709-
.iter()
710-
.filter(|pkg| pkg.publish() == &Some(Vec::new()))
711-
.map(|pkg| format!("`{}`", pkg.name()))
712-
.collect::<Vec<_>>();
713-
if !unpublishable.is_empty() {
714-
bail!(
715-
"{} cannot be published.\n\
716-
`package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish.",
717-
unpublishable.join(", ")
718-
);
719-
}
720-
721722
let reg_name = match reg_or_index {
722723
Some(RegistryOrIndex::Registry(r)) => Some(r.as_str()),
723724
None => Some(CRATES_IO_REGISTRY),

0 commit comments

Comments
 (0)