mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
refactor(publish): extract "no publishable found" error
This commit is contained in:
parent
2421496c92
commit
6f8136488e
@ -93,6 +93,20 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
|
|||||||
.filter(|(m, _)| specs.iter().any(|spec| spec.matches(m.package_id())))
|
.filter(|(m, _)| specs.iter().any(|spec| spec.matches(m.package_id())))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
let (unpublishable, pkgs): (Vec<_>, Vec<_>) = pkgs
|
||||||
|
.into_iter()
|
||||||
|
.partition(|(pkg, _)| pkg.publish() == &Some(vec![]));
|
||||||
|
if !unpublishable.is_empty() {
|
||||||
|
bail!(
|
||||||
|
"{} cannot be published.\n\
|
||||||
|
`package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish.",
|
||||||
|
unpublishable
|
||||||
|
.iter()
|
||||||
|
.map(|(pkg, _)| format!("`{}`", pkg.name()))
|
||||||
|
.join(", "),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
let just_pkgs: Vec<_> = pkgs.iter().map(|p| p.0).collect();
|
let just_pkgs: Vec<_> = pkgs.iter().map(|p| p.0).collect();
|
||||||
let reg_or_index = match opts.reg_or_index.clone() {
|
let reg_or_index = match opts.reg_or_index.clone() {
|
||||||
Some(r) => {
|
Some(r) => {
|
||||||
@ -705,19 +719,6 @@ fn package_list(pkgs: impl IntoIterator<Item = PackageId>, final_sep: &str) -> S
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn validate_registry(pkgs: &[&Package], reg_or_index: Option<&RegistryOrIndex>) -> CargoResult<()> {
|
fn validate_registry(pkgs: &[&Package], reg_or_index: Option<&RegistryOrIndex>) -> CargoResult<()> {
|
||||||
let unpublishable = pkgs
|
|
||||||
.iter()
|
|
||||||
.filter(|pkg| pkg.publish() == &Some(Vec::new()))
|
|
||||||
.map(|pkg| format!("`{}`", pkg.name()))
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
if !unpublishable.is_empty() {
|
|
||||||
bail!(
|
|
||||||
"{} cannot be published.\n\
|
|
||||||
`package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish.",
|
|
||||||
unpublishable.join(", ")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let reg_name = match reg_or_index {
|
let reg_name = match reg_or_index {
|
||||||
Some(RegistryOrIndex::Registry(r)) => Some(r.as_str()),
|
Some(RegistryOrIndex::Registry(r)) => Some(r.as_str()),
|
||||||
None => Some(CRATES_IO_REGISTRY),
|
None => Some(CRATES_IO_REGISTRY),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user