fix: remove list owners feature of info subcommand

This commit is contained in:
hi-rustin 2024-08-17 11:21:59 +08:00
parent ff6df29857
commit 866afb2106
8 changed files with 13 additions and 108 deletions

View File

@ -1,9 +1,7 @@
//! Implementation of `cargo info`.
use anyhow::bail;
use cargo_credential::Operation;
use cargo_util_schemas::core::{PackageIdSpec, PartialVersion};
use crates_io::User;
use crate::core::registry::PackageRegistry;
use crate::core::{Dependency, Package, PackageId, PackageIdSpecQuery, Registry, Workspace};
@ -12,7 +10,6 @@ use crate::ops::registry::{get_source_id_with_package_id, RegistryOrIndex, Regis
use crate::ops::resolve_ws;
use crate::sources::source::QueryKind;
use crate::sources::{IndexSummary, SourceConfigMap};
use crate::util::auth::AuthorizationErrorReason;
use crate::util::cache_lock::CacheLockMode;
use crate::util::command_prelude::root_manifest;
use crate::{CargoResult, GlobalContext};
@ -79,19 +76,7 @@ pub fn info(
let package = registry.get(&[package_id])?;
let package = package.get_one(package_id)?;
let owners = try_list_owners(
gctx,
&source_ids,
reg_or_index.as_ref(),
package_id.name().as_str(),
)?;
pretty_view(
package,
&summaries,
&owners,
suggest_cargo_tree_command,
gctx,
)?;
pretty_view(package, &summaries, suggest_cargo_tree_command, gctx)?;
Ok(())
}
@ -207,56 +192,6 @@ fn query_summaries(
}
}
// Try to list the login and name of all owners of a crate.
fn try_list_owners(
gctx: &GlobalContext,
source_ids: &RegistrySourceIds,
reg_or_index: Option<&RegistryOrIndex>,
package_name: &str,
) -> CargoResult<Option<Vec<String>>> {
// Only remote registries support listing owners.
if !source_ids.original.is_remote_registry() {
return Ok(None);
}
match super::registry(
gctx,
source_ids,
None,
reg_or_index,
false,
Some(Operation::Read),
) {
Ok(mut registry) => {
let owners = registry.list_owners(package_name)?;
let names = owners.iter().map(get_username).collect();
return Ok(Some(names));
}
Err(err) => {
// If the token is missing, it means the user is not logged in.
// We don't want to show an error in this case.
if err.to_string().contains(
(AuthorizationErrorReason::TokenMissing)
.to_string()
.as_str(),
) {
return Ok(None);
}
return Err(err);
}
}
}
fn get_username(u: &User) -> String {
format!(
"{}{}",
u.login,
u.name
.as_ref()
.map(|name| format!(" ({})", name))
.unwrap_or_default(),
)
}
fn validate_locked_and_frozen_options(
in_workspace: bool,
gctx: &GlobalContext,

View File

@ -15,7 +15,6 @@ use crate::{
pub(super) fn pretty_view(
package: &Package,
summaries: &[IndexSummary],
owners: &Option<Vec<String>>,
suggest_cargo_tree_command: bool,
gctx: &GlobalContext,
) -> CargoResult<()> {
@ -153,10 +152,6 @@ pub(super) fn pretty_view(
gctx,
)?;
if let Some(owners) = owners {
pretty_owners(owners, stdout)?;
}
if suggest_cargo_tree_command {
suggest_cargo_tree(package_id, stdout)?;
}
@ -399,19 +394,6 @@ fn pretty_features(
Ok(())
}
fn pretty_owners(owners: &Vec<String>, stdout: &mut dyn Write) -> CargoResult<()> {
let header = HEADER;
if !owners.is_empty() {
writeln!(stdout, "{header}owners:{header:#}",)?;
for owner in owners {
writeln!(stdout, " {}", owner)?;
}
}
Ok(())
}
// Suggest the cargo tree command to view the dependency tree.
fn suggest_cargo_tree(package_id: PackageId, stdout: &mut dyn Write) -> CargoResult<()> {
let literal = LITERAL;

View File

@ -1,4 +1,4 @@
<svg width="740px" height="110px" xmlns="http://www.w3.org/2000/svg">
<svg width="740px" height="92px" xmlns="http://www.w3.org/2000/svg">
<style>
.fg { fill: #AAAAAA }
.bg { background: #000000 }
@ -24,9 +24,7 @@
</tspan>
<tspan x="10px" y="64px"><tspan class="fg-green bold"> Downloaded</tspan><tspan> your-face v99999.0.0+my-package (registry `dummy-registry`)</tspan>
</tspan>
<tspan x="10px" y="82px"><tspan class="fg-green bold"> Credential</tspan><tspan> cargo:token get dummy-registry</tspan>
</tspan>
<tspan x="10px" y="100px">
<tspan x="10px" y="82px">
</tspan>
</text>

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1006 B

View File

@ -1,4 +1,4 @@
<svg width="740px" height="110px" xmlns="http://www.w3.org/2000/svg">
<svg width="740px" height="92px" xmlns="http://www.w3.org/2000/svg">
<style>
.fg { fill: #AAAAAA }
.bg { background: #000000 }
@ -24,9 +24,7 @@
</tspan>
<tspan x="10px" y="64px"><tspan class="fg-green bold"> Downloaded</tspan><tspan> my-package v0.1.1+my-package (registry `dummy-registry`)</tspan>
</tspan>
<tspan x="10px" y="82px"><tspan class="fg-green bold"> Updating</tspan><tspan> crates.io index</tspan>
</tspan>
<tspan x="10px" y="100px">
<tspan x="10px" y="82px">
</tspan>
</text>

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1003 B

View File

@ -1,4 +1,4 @@
<svg width="740px" height="110px" xmlns="http://www.w3.org/2000/svg">
<svg width="740px" height="92px" xmlns="http://www.w3.org/2000/svg">
<style>
.fg { fill: #AAAAAA }
.bg { background: #000000 }
@ -24,9 +24,7 @@
</tspan>
<tspan x="10px" y="64px"><tspan class="fg-green bold"> Downloaded</tspan><tspan> my-package v2.0.0 (registry `dummy-registry`)</tspan>
</tspan>
<tspan x="10px" y="82px"><tspan class="fg-green bold"> Updating</tspan><tspan> crates.io index</tspan>
</tspan>
<tspan x="10px" y="100px">
<tspan x="10px" y="82px">
</tspan>
</text>

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 992 B

View File

@ -1,4 +1,4 @@
<svg width="740px" height="110px" xmlns="http://www.w3.org/2000/svg">
<svg width="740px" height="92px" xmlns="http://www.w3.org/2000/svg">
<style>
.fg { fill: #AAAAAA }
.bg { background: #000000 }
@ -24,9 +24,7 @@
</tspan>
<tspan x="10px" y="64px"><tspan class="fg-green bold"> Downloaded</tspan><tspan> my-package v0.1.0 (registry `dummy-registry`)</tspan>
</tspan>
<tspan x="10px" y="82px"><tspan class="fg-green bold"> Credential</tspan><tspan> cargo:token get dummy-registry</tspan>
</tspan>
<tspan x="10px" y="100px">
<tspan x="10px" y="82px">
</tspan>
</text>

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 992 B

View File

@ -1,4 +1,4 @@
<svg width="740px" height="110px" xmlns="http://www.w3.org/2000/svg">
<svg width="740px" height="92px" xmlns="http://www.w3.org/2000/svg">
<style>
.fg { fill: #AAAAAA }
.bg { background: #000000 }
@ -24,9 +24,7 @@
</tspan>
<tspan x="10px" y="64px"><tspan class="fg-green bold"> Downloaded</tspan><tspan> my-package v0.1.1+my-package (registry `dummy-registry`)</tspan>
</tspan>
<tspan x="10px" y="82px"><tspan class="fg-green bold"> Updating</tspan><tspan> crates.io index</tspan>
</tspan>
<tspan x="10px" y="100px">
<tspan x="10px" y="82px">
</tspan>
</text>

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1003 B

View File

@ -1,4 +1,4 @@
<svg width="740px" height="146px" xmlns="http://www.w3.org/2000/svg">
<svg width="740px" height="128px" xmlns="http://www.w3.org/2000/svg">
<style>
.fg { fill: #AAAAAA }
.bg { background: #000000 }
@ -30,9 +30,7 @@
</tspan>
<tspan x="10px" y="100px"><tspan class="fg-green bold"> Downloaded</tspan><tspan> my-package v0.2.3+my-package (registry `dummy-registry`)</tspan>
</tspan>
<tspan x="10px" y="118px"><tspan class="fg-green bold"> Updating</tspan><tspan> crates.io index</tspan>
</tspan>
<tspan x="10px" y="136px">
<tspan x="10px" y="118px">
</tspan>
</text>

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB