1 //! Interacts with the registry [yank] and [unyank] API.
3 //! [yank]: https://doc.rust-lang.org/nightly/cargo/reference/registry-web-api.html#yank
4 //! [unyank]: https://doc.rust-lang.org/nightly/cargo/reference/registry-web-api.html#unyank
7 use anyhow
::Context
as _
;
8 use cargo_credential
::Operation
;
9 use cargo_credential
::Secret
;
11 use crate::core
::Workspace
;
12 use crate::util
::config
::Config
;
13 use crate::util
::errors
::CargoResult
;
14 use crate::util
::important_paths
::find_root_manifest_for_wd
;
16 use super::RegistryOrIndex
;
20 krate
: Option
<String
>,
21 version
: Option
<String
>,
22 token
: Option
<Secret
<String
>>,
23 reg_or_index
: Option
<RegistryOrIndex
>,
25 ) -> CargoResult
<()> {
26 let name
= match krate
{
29 let manifest_path
= find_root_manifest_for_wd(config
.cwd())?
;
30 let ws
= Workspace
::new(&manifest_path
, config
)?
;
31 ws
.current()?
.package_id().name().to_string()
34 let Some(version
) = version
else {
35 bail
!("a version must be specified to yank")
38 let message
= if undo
{
50 let (mut registry
, _
) = super::registry(
52 token
.as_ref().map(Secret
::as_deref
),
53 reg_or_index
.as_ref(),
58 let package_spec
= format
!("{}@{}", name
, version
);
60 config
.shell().status("Unyank", package_spec
)?
;
61 registry
.unyank(&name
, &version
).with_context(|| {
63 "failed to undo a yank from the registry at {}",
68 config
.shell().status("Yank", package_spec
)?
;
70 .yank(&name
, &version
)
71 .with_context(|| format
!("failed to yank from the registry at {}", registry
.host()))?
;