Skip to content

Commit af2c355

Browse files
committed
Show the command summary when running cargo --list
1 parent c3422cf commit af2c355

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

src/bin/cargo/cli.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ Run with 'cargo -Z [FLAG] [SUBCOMMAND]'"
7070
println!("Installed Commands:");
7171
for command in list_commands(config) {
7272
match command {
73-
CommandInfo::BuiltIn { name } => {
74-
println!(" {:<20} {}", name)
73+
CommandInfo::BuiltIn { name, about } => {
74+
let summary = about.unwrap_or_default();
75+
println!(" {:<20} {}", name, summary)
7576
}
7677
CommandInfo::External { name, path } => {
7778
if is_verbose {

src/bin/cargo/command_prelude.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ pub fn values(args: &ArgMatches, name: &str) -> Vec<String> {
414414

415415
#[derive(PartialEq, PartialOrd, Eq, Ord)]
416416
pub enum CommandInfo {
417-
BuiltIn { name: String },
417+
BuiltIn { name: String, about: Option<String>, },
418418
External { name: String, path: PathBuf },
419419
}
420420

src/bin/cargo/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ fn list_commands(config: &Config) -> BTreeSet<CommandInfo> {
114114
for cmd in commands::builtin() {
115115
commands.insert(CommandInfo::BuiltIn {
116116
name: cmd.get_name().to_string(),
117+
about: cmd.p.meta.about.map(|s| s.to_string()),
117118
});
118119
}
119120

tests/testsuite/cargo_command.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ fn path() -> Vec<PathBuf> {
6060
env::split_paths(&env::var_os("PATH").unwrap_or_default()).collect()
6161
}
6262

63+
#[test]
64+
fn list_commands_with_descriptions() {
65+
let p = project().build();
66+
let output = p.cargo("--list").exec_with_output().unwrap();
67+
let output = str::from_utf8(&output.stdout).unwrap();
68+
assert!(
69+
output.contains("\n build Compile a local package and all of its dependencies"),
70+
"missing build, with description: {}",
71+
output
72+
);
73+
}
74+
6375
#[test]
6476
fn list_command_looks_at_path() {
6577
let proj = project().build();

0 commit comments

Comments
 (0)