Show the command summary when running cargo --list

This commit is contained in:
Dale Wijnand 2018-07-26 12:08:39 +01:00
parent c3422cfc40
commit af2c355585
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF
4 changed files with 17 additions and 3 deletions

View File

@ -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 {

View File

@ -414,7 +414,7 @@ pub fn values(args: &ArgMatches, name: &str) -> Vec<String> {
#[derive(PartialEq, PartialOrd, Eq, Ord)]
pub enum CommandInfo {
BuiltIn { name: String },
BuiltIn { name: String, about: Option<String>, },
External { name: String, path: PathBuf },
}

View File

@ -114,6 +114,7 @@ fn list_commands(config: &Config) -> BTreeSet<CommandInfo> {
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()),
});
}

View File

@ -60,6 +60,18 @@ fn path() -> Vec<PathBuf> {
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();