Skip to content

Commit

Permalink
feat: Put dependencies behind --verbose
Browse files Browse the repository at this point in the history
With public/private dependencies, we can at least show those.

Fixes hi-rustin#23
  • Loading branch information
epage committed Mar 19, 2024
1 parent d140c5e commit 49ad0a6
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 19 deletions.
21 changes: 18 additions & 3 deletions src/ops/view.rs
@@ -1,7 +1,9 @@
use std::io::Write;

use cargo::{
core::{dependency::DepKind, Dependency, FeatureMap, Package, PackageId, SourceId},
core::{
dependency::DepKind, shell::Verbosity, Dependency, FeatureMap, Package, PackageId, SourceId,
},
sources::IndexSummary,
CargoResult, Config,
};
Expand All @@ -25,6 +27,7 @@ pub(super) fn pretty_view(
let note = NOTE;

let mut shell = config.shell();
let verbosity = shell.verbosity();
let stdout = shell.out();
write!(stdout, "{header}{}{header:#}", package_id.name())?;
if !metadata.keywords.is_empty() {
Expand Down Expand Up @@ -118,7 +121,7 @@ pub(super) fn pretty_view(

pretty_features(summary.features(), stdout)?;

pretty_deps(package, stdout, config)?;
pretty_deps(package, verbosity, stdout, config)?;

if let Some(owners) = owners {
pretty_owners(owners, stdout)?;
Expand All @@ -143,7 +146,19 @@ fn pretty_source(source: SourceId, config: &Config) -> String {
}
}

fn pretty_deps(package: &Package, stdout: &mut dyn Write, config: &Config) -> CargoResult<()> {
fn pretty_deps(
package: &Package,
verbosity: Verbosity,
stdout: &mut dyn Write,
config: &Config,
) -> CargoResult<()> {
match verbosity {
Verbosity::Quiet | Verbosity::Normal => {
return Ok(());
}
Verbosity::Verbose => {}
}

let header = HEADER;

let dependencies = package
Expand Down
12 changes: 2 additions & 10 deletions tests/testsuite/cargo_information/basic/stdout.term.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/testsuite/cargo_information/git_dependency/mod.rs
@@ -1,5 +1,5 @@
use cargo_test_macro::cargo_test;
use cargo_test_support::{basic_manifest, file, git, project};
use cargo_test_support::{basic_manifest, file, git, project, ArgLine as _};

use super::{cargo_info, init_registry_without_token};

Expand Down Expand Up @@ -34,7 +34,7 @@ fn case() {
let cwd = &project_root;

cargo_info()
.arg("foo")
.arg_line("--verbose foo")
.current_dir(cwd)
.assert()
.success()
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/cargo_information/mod.rs
Expand Up @@ -14,6 +14,7 @@ mod specify_version_outside_ws;
mod specify_version_with_url_but_registry_is_not_matched;
mod specify_version_within_ws_and_conflict_with_lockfile;
mod specify_version_within_ws_and_match_with_lockfile;
mod verbose;
mod with_frozen_outside_ws;
mod with_frozen_within_ws;
mod with_locked_outside_ws;
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/cargo_information/path_dependency/mod.rs
@@ -1,5 +1,5 @@
use cargo_test_macro::cargo_test;
use cargo_test_support::{compare::assert_ui, current_dir, file, Project};
use cargo_test_support::{compare::assert_ui, current_dir, file, ArgLine as _, Project};

use super::{cargo_info, init_registry_without_token};

Expand All @@ -12,7 +12,7 @@ fn case() {
let cwd = &project_root;

cargo_info()
.arg("foo")
.arg_line("--verbose foo")
.current_dir(cwd)
.assert()
.success()
Expand Down
52 changes: 52 additions & 0 deletions tests/testsuite/cargo_information/verbose/mod.rs
@@ -0,0 +1,52 @@
use cargo_test_macro::cargo_test;
use cargo_test_support::file;

use super::{cargo_info_with_color, init_registry_without_token};

#[cargo_test]
fn case() {
init_registry_without_token();
cargo_test_support::registry::Package::new("my-package", "0.1.0")
.file(
"Cargo.toml",
r#"
[package]
name = "my-package"
version = "0.1.0"
description = "A package for testing"
repository = "https://github.com/hi-rustin/cargo-infromation"
documentation = "https://docs.rs/my-package/0.1.0"
license = "MIT"
edition = "2018"
rust-version = "1.50.0"
keywords = ["foo", "bar", "baz"]
[features]
default = ["feature1"]
feature1 = []
feature2 = []
[dependencies]
foo = "0.1.0"
bar = "0.2.0"
baz = { version = "0.3.0", optional = true }
[[bin]]
name = "my_bin"
[lib]
name = "my_lib"
"#,
)
.file("src/bin/my_bin.rs", "")
.file("src/lib.rs", "")
.publish();
cargo_info_with_color()
.arg("my-package")
.arg("--verbose")
.arg("--registry=dummy-registry")
.assert()
.success()
.stdout_matches(file!["stdout.term.svg"])
.stderr_matches(file!["stderr.term.svg"]);
}
33 changes: 33 additions & 0 deletions tests/testsuite/cargo_information/verbose/stderr.term.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions tests/testsuite/cargo_information/verbose/stdout.term.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Expand Up @@ -2,5 +2,3 @@ cargo-list-test-fixture
version: 0.2.0 (from ./)
license: unknown
rust-version: unknown
dependencies:
my-package@0.1

0 comments on commit 49ad0a6

Please sign in to comment.