Skip to content

Commit 52f8487

Browse files
committed
Suggest cargo info command in the cargo search result
1 parent e7ca9be commit 52f8487

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/cargo/ops/registry/search.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use anyhow::Context as _;
88
use url::Url;
99

1010
use crate::util::style;
11+
use crate::util::style::LITERAL;
1112
use crate::util::truncate_with_ellipsis;
1213
use crate::CargoResult;
1314
use crate::GlobalContext;
@@ -87,5 +88,12 @@ pub fn search(
8788
);
8889
}
8990

91+
if total_crates > 0 {
92+
let literal = LITERAL;
93+
shell.note(format_args!(
94+
"to learn more about a package, run `{literal}cargo info <name>{literal:#}`",
95+
))?;
96+
}
97+
9098
Ok(())
9199
}

tests/testsuite/search.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,11 @@ fn not_update() {
115115
cargo_process("search postgres")
116116
.replace_crates_io(registry.index_url())
117117
.with_stdout_data(SEARCH_RESULTS)
118-
.with_stderr_data("") // without "Updating ... index"
118+
// without "Updating ... index"
119+
.with_stderr_data(str![[r#"
120+
[NOTE] to learn more about a package, run `cargo info <name>`
121+
122+
"#]])
119123
.run();
120124
}
121125

@@ -128,6 +132,7 @@ fn replace_default() {
128132
.with_stdout_data(SEARCH_RESULTS)
129133
.with_stderr_data(str![[r#"
130134
[UPDATING] crates.io index
135+
[NOTE] to learn more about a package, run `cargo info <name>`
131136
132137
"#]])
133138
.run();
@@ -140,6 +145,11 @@ fn simple() {
140145
cargo_process("search postgres --index")
141146
.arg(registry.index_url().as_str())
142147
.with_stdout_data(SEARCH_RESULTS)
148+
.with_stderr_data(str![[r#"
149+
[UPDATING] `[ROOT]/registry` index
150+
[NOTE] to learn more about a package, run `cargo info <name>`
151+
152+
"#]])
143153
.run();
144154
}
145155

@@ -150,6 +160,11 @@ fn multiple_query_params() {
150160
cargo_process("search postgres sql --index")
151161
.arg(registry.index_url().as_str())
152162
.with_stdout_data(SEARCH_RESULTS)
163+
.with_stderr_data(str![[r#"
164+
[UPDATING] `[ROOT]/registry` index
165+
[NOTE] to learn more about a package, run `cargo info <name>`
166+
167+
"#]])
153168
.run();
154169
}
155170

0 commit comments

Comments
 (0)