@@ -3,12 +3,23 @@ use cargo::core::{features, CliUnstable};
3
3
use cargo:: { self , drop_print, drop_println, CliResult , Config } ;
4
4
use clap:: { AppSettings , Arg , ArgMatches } ;
5
5
use itertools:: Itertools ;
6
+ use std:: collections:: HashMap ;
6
7
7
8
use super :: commands;
8
9
use super :: list_commands;
9
10
use crate :: command_prelude:: * ;
10
11
use cargo:: core:: features:: HIDDEN ;
11
12
13
+ lazy_static:: lazy_static! {
14
+ // Maps from commonly known external commands (not builtin to cargo) to their
15
+ // description, for the help page. Reserved for external subcommands that are
16
+ // core within the rust ecosystem (esp ones that might become internal in the future).
17
+ static ref KNOWN_EXTERNAL_COMMAND_DESCRIPTIONS : HashMap <& ' static str , & ' static str > = vec![
18
+ ( "clippy" , "Checks a package to catch common mistakes and improve your Rust code." ) ,
19
+ ( "fmt" , "Formats all bin and lib files of the current crate using rustfmt." ) ,
20
+ ] . into_iter( ) . collect( ) ;
21
+ }
22
+
12
23
pub fn main ( config : & mut Config ) -> CliResult {
13
24
// CAUTION: Be careful with using `config` until it is configured below.
14
25
// In general, try to avoid loading config values unless necessary (like
@@ -100,14 +111,22 @@ Run with 'cargo -Z [FLAG] [SUBCOMMAND]'",
100
111
if args. is_present ( "list" ) {
101
112
drop_println ! ( config, "Installed Commands:" ) ;
102
113
for ( name, command) in list_commands ( config) {
114
+ let known_external_desc = KNOWN_EXTERNAL_COMMAND_DESCRIPTIONS . get ( name. as_str ( ) ) ;
103
115
match command {
104
116
CommandInfo :: BuiltIn { about } => {
117
+ assert ! (
118
+ known_external_desc. is_none( ) ,
119
+ "KNOWN_EXTERNAL_COMMANDS shouldn't contain builtin \" {}\" " ,
120
+ name
121
+ ) ;
105
122
let summary = about. unwrap_or_default ( ) ;
106
123
let summary = summary. lines ( ) . next ( ) . unwrap_or ( & summary) ; // display only the first line
107
124
drop_println ! ( config, " {:<20} {}" , name, summary) ;
108
125
}
109
126
CommandInfo :: External { path } => {
110
- if is_verbose {
127
+ if let Some ( desc) = known_external_desc {
128
+ drop_println ! ( config, " {:<20} {}" , name, desc) ;
129
+ } else if is_verbose {
111
130
drop_println ! ( config, " {:<20} {}" , name, path. display( ) ) ;
112
131
} else {
113
132
drop_println ! ( config, " {}" , name) ;
0 commit comments