From af2c355585887db60b8da28024aba3b2ab95edfe Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Thu, 26 Jul 2018 12:08:39 +0100 Subject: [PATCH] Show the command summary when running cargo --list --- src/bin/cargo/cli.rs | 5 +++-- src/bin/cargo/command_prelude.rs | 2 +- src/bin/cargo/main.rs | 1 + tests/testsuite/cargo_command.rs | 12 ++++++++++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/bin/cargo/cli.rs b/src/bin/cargo/cli.rs index 85990c8f0..3eb7f27be 100644 --- a/src/bin/cargo/cli.rs +++ b/src/bin/cargo/cli.rs @@ -70,8 +70,9 @@ Run with 'cargo -Z [FLAG] [SUBCOMMAND]'" println!("Installed Commands:"); for command in list_commands(config) { match command { - CommandInfo::BuiltIn { name } => { - println!(" {:<20} {}", name) + CommandInfo::BuiltIn { name, about } => { + let summary = about.unwrap_or_default(); + println!(" {:<20} {}", name, summary) } CommandInfo::External { name, path } => { if is_verbose { diff --git a/src/bin/cargo/command_prelude.rs b/src/bin/cargo/command_prelude.rs index 59aef526d..e40619b30 100644 --- a/src/bin/cargo/command_prelude.rs +++ b/src/bin/cargo/command_prelude.rs @@ -414,7 +414,7 @@ pub fn values(args: &ArgMatches, name: &str) -> Vec { #[derive(PartialEq, PartialOrd, Eq, Ord)] pub enum CommandInfo { - BuiltIn { name: String }, + BuiltIn { name: String, about: Option, }, External { name: String, path: PathBuf }, } diff --git a/src/bin/cargo/main.rs b/src/bin/cargo/main.rs index f2bf93bc9..18643a97e 100644 --- a/src/bin/cargo/main.rs +++ b/src/bin/cargo/main.rs @@ -114,6 +114,7 @@ fn list_commands(config: &Config) -> BTreeSet { for cmd in commands::builtin() { commands.insert(CommandInfo::BuiltIn { name: cmd.get_name().to_string(), + about: cmd.p.meta.about.map(|s| s.to_string()), }); } diff --git a/tests/testsuite/cargo_command.rs b/tests/testsuite/cargo_command.rs index a754eeefe..ffe020ad0 100644 --- a/tests/testsuite/cargo_command.rs +++ b/tests/testsuite/cargo_command.rs @@ -60,6 +60,18 @@ fn path() -> Vec { env::split_paths(&env::var_os("PATH").unwrap_or_default()).collect() } +#[test] +fn list_commands_with_descriptions() { + let p = project().build(); + let output = p.cargo("--list").exec_with_output().unwrap(); + let output = str::from_utf8(&output.stdout).unwrap(); + assert!( + output.contains("\n build Compile a local package and all of its dependencies"), + "missing build, with description: {}", + output + ); +} + #[test] fn list_command_looks_at_path() { let proj = project().build();