Skip to content

Commit 5e77adf

Browse files
committed
Port some more publish messages
1 parent 4581ba8 commit 5e77adf

File tree

2 files changed

+58
-32
lines changed

2 files changed

+58
-32
lines changed

src/cargo/ops/registry/publish.rs

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::io::Seek;
1111
use std::io::SeekFrom;
1212
use std::time::Duration;
1313

14+
use annotate_snippets::Level;
1415
use anyhow::Context as _;
1516
use anyhow::bail;
1617
use cargo_credential::Operation;
@@ -108,12 +109,16 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
108109
if allow_unpublishable {
109110
let n = unpublishable.len();
110111
let plural = if n == 1 { "" } else { "s" };
111-
ws.gctx().shell().warn(format_args!(
112-
"nothing to publish, but found {n} unpublishable package{plural}"
113-
))?;
114-
ws.gctx().shell().note(format_args!(
115-
"to publish packages, set `package.publish` to `true` or a non-empty list"
116-
))?;
112+
ws.gctx().shell().print_report(
113+
&[Level::WARNING
114+
.secondary_title(format!(
115+
"nothing to publish, but found {n} unpublishable package{plural}"
116+
))
117+
.element(Level::HELP.message(
118+
"to publish packages, set `package.publish` to `true` or a non-empty list",
119+
))],
120+
false,
121+
)?;
117122
return Ok(());
118123
} else {
119124
unreachable!("must have at least one publishable package");
@@ -323,18 +328,23 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
323328
)?;
324329
} else {
325330
let short_pkg_descriptions = package_list(to_confirm.iter().copied(), "or");
326-
opts.gctx.shell().warn(format!(
327-
"timed out waiting for {short_pkg_descriptions} to be available in {source_description}",
328-
))?;
329-
opts.gctx.shell().note(format!(
330-
"the registry may have a backlog that is delaying making the \
331-
{crate} available. The {crate} should be available soon.",
332-
crate = if to_confirm.len() == 1 {
333-
"crate"
334-
} else {
335-
"crates"
336-
}
337-
))?;
331+
let krate = if to_confirm.len() == 1 {
332+
"crate"
333+
} else {
334+
"crates"
335+
};
336+
opts.gctx.shell().print_report(
337+
&[Level::WARNING
338+
.secondary_title(format!(
339+
"timed out waiting for {short_pkg_descriptions} \
340+
to be available in {source_description}",
341+
))
342+
.element(Level::NOTE.message(format!(
343+
"the registry may have a backlog that is delaying making the \
344+
{krate} available. The {krate} should be available soon.",
345+
)))],
346+
false,
347+
)?;
338348
}
339349
confirmed
340350
} else {
@@ -676,25 +686,38 @@ fn transmit(
676686

677687
if !warnings.invalid_categories.is_empty() {
678688
let msg = format!(
679-
"the following are not valid category slugs and were \
680-
ignored: {}. Please see https://crates.io/category_slugs \
681-
for the list of all category slugs. \
682-
",
689+
"the following are not valid category slugs and were ignored: {}",
683690
warnings.invalid_categories.join(", ")
684691
);
685-
gctx.shell().warn(&msg)?;
692+
gctx.shell().print_report(
693+
&[Level::WARNING
694+
.secondary_title(msg)
695+
.element(Level::HELP.message(
696+
"please see <https://crates.io/category_slugs> for the list of all category slugs",
697+
))],
698+
false,
699+
)?;
686700
}
687701

688702
if !warnings.invalid_badges.is_empty() {
689703
let msg = format!(
690-
"the following are not valid badges and were ignored: {}. \
691-
Either the badge type specified is unknown or a required \
692-
attribute is missing. Please see \
693-
https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata \
694-
for valid badge types and their required attributes.",
704+
"the following are not valid badges and were ignored: {}",
695705
warnings.invalid_badges.join(", ")
696706
);
697-
gctx.shell().warn(&msg)?;
707+
gctx.shell().print_report(
708+
&[Level::WARNING.secondary_title(msg).elements([
709+
Level::NOTE.message(
710+
"either the badge type specified is unknown or a required \
711+
attribute is missing",
712+
),
713+
Level::HELP.message(
714+
"please see \
715+
<https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata> \
716+
for valid badge types and their required attributes",
717+
),
718+
])],
719+
false,
720+
)?;
698721
}
699722

700723
if !warnings.other.is_empty() {

tests/testsuite/publish.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3361,7 +3361,8 @@ fn timeout_waiting_for_publish() {
33613361
[NOTE] waiting for delay v0.0.1 to be available at registry `crates-io`
33623362
[HELP] you may press ctrl-c to skip waiting; the crate should be available shortly
33633363
[WARNING] timed out waiting for delay v0.0.1 to be available in registry `crates-io`
3364-
[NOTE] the registry may have a backlog that is delaying making the crate available. The crate should be available soon.
3364+
|
3365+
= [NOTE] the registry may have a backlog that is delaying making the crate available. The crate should be available soon.
33653366
33663367
"#]])
33673368
.run();
@@ -3463,7 +3464,8 @@ fn timeout_waiting_for_dependency_publish() {
34633464
[NOTE] waiting for dep v0.0.1 to be available at registry `crates-io`.
34643465
2 remaining crates to be published
34653466
[WARNING] timed out waiting for dep v0.0.1 to be available in registry `crates-io`
3466-
[NOTE] the registry may have a backlog that is delaying making the crate available. The crate should be available soon.
3467+
|
3468+
= [NOTE] the registry may have a backlog that is delaying making the crate available. The crate should be available soon.
34673469
[ERROR] unable to publish main v0.0.1 and other v0.0.1 due to a timeout while waiting for published dependencies to be available.
34683470
34693471
"#]])
@@ -4361,7 +4363,8 @@ fn all_unpublishable_packages() {
43614363
.replace_crates_io(registry.index_url())
43624364
.with_stderr_data(str![[r#"
43634365
[WARNING] nothing to publish, but found 2 unpublishable packages
4364-
[NOTE] to publish packages, set `package.publish` to `true` or a non-empty list
4366+
|
4367+
= [HELP] to publish packages, set `package.publish` to `true` or a non-empty list
43654368
43664369
"#]])
43674370
.run();

0 commit comments

Comments
 (0)