Skip to content

Commit

Permalink
Auto merge of #14554 - Rustin170506:rustin-patch-notes, r=epage
Browse files Browse the repository at this point in the history
refactor(info): Use the `shell.note` to print the note
  • Loading branch information
bors committed Sep 17, 2024
2 parents 25456ea + 0ba7540 commit 1eb49a1
Show file tree
Hide file tree
Showing 20 changed files with 136 additions and 73 deletions.
18 changes: 5 additions & 13 deletions src/cargo/ops/registry/info/view.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;
use std::io::Write;

use crate::core::Shell;
use crate::util::style::{ERROR, HEADER, LITERAL, NOP, NOTE, WARN};
use crate::{
core::{
Expand Down Expand Up @@ -153,7 +154,7 @@ pub(super) fn pretty_view(
)?;

if suggest_cargo_tree_command {
suggest_cargo_tree(package_id, stdout)?;
suggest_cargo_tree(package_id, &mut shell)?;
}

Ok(())
Expand Down Expand Up @@ -395,23 +396,14 @@ fn pretty_features(
}

// Suggest the cargo tree command to view the dependency tree.
fn suggest_cargo_tree(package_id: PackageId, stdout: &mut dyn Write) -> CargoResult<()> {
fn suggest_cargo_tree(package_id: PackageId, shell: &mut Shell) -> CargoResult<()> {
let literal = LITERAL;

note(format_args!(
shell.note(format_args!(
"to see how you depend on {name}, run `{literal}cargo tree --invert --package {name}@{version}{literal:#}`",
name = package_id.name(),
version = package_id.version(),
), stdout)
}

pub(super) fn note(msg: impl std::fmt::Display, stdout: &mut dyn Write) -> CargoResult<()> {
let note = NOTE;
let bold = anstyle::Style::new() | anstyle::Effects::BOLD;

writeln!(stdout, "{note}note{note:#}{bold}:{bold:#} {msg}",)?;

Ok(())
))
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ fn case() {
.current_dir(transitive1_directory)
.assert()
.stdout_eq(file!["transitive1-stdout.term.svg"])
.stderr_eq("");
.stderr_eq(file!["transitive1-stderr.term.svg"]);
snapbox::cmd::Command::cargo_ui()
.arg("info")
.arg("my-package")
.arg("--registry=dummy-registry")
.current_dir(transitive2_directory)
.assert()
.stdout_eq(file!["transitive2-stdout.term.svg"])
.stderr_eq("");
.stderr_eq(file!["transitive2-stderr.term.svg"]);
snapbox::cmd::Command::cargo_ui()
.arg("info")
.arg("my-package")
Expand All @@ -72,7 +72,7 @@ fn case() {
.current_dir(direct2_directory)
.assert()
.stdout_eq(file!["direct2-stdout.term.svg"])
.stderr_eq("");
.stderr_eq(file!["direct2-stderr.term.svg"]);

assert_ui().subset_matches(current_dir!().join("out"), &project_root);
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions tests/testsuite/cargo_info/within_ws/stderr.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 2 additions & 5 deletions tests/testsuite/cargo_info/within_ws/stdout.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 1eb49a1

Please sign in to comment.