@@ -30,21 +30,46 @@ pub(crate) fn description(roff: &mut Roff, cmd: &clap::Command) {
30
30
}
31
31
32
32
pub ( crate ) fn synopsis ( roff : & mut Roff , cmd : & clap:: Command ) {
33
- let name = cmd. get_bin_name ( ) . unwrap_or_else ( || cmd. get_name ( ) ) ;
34
- let mut line = vec ! [ bold( name) , roman( " " ) ] ;
35
- let mut line = usage ( cmd, name) ;
36
-
37
- if cmd. has_subcommands ( ) && !flatten {
38
- let ( lhs, rhs) = subcommand_markers ( cmd) ;
39
- line. push ( roman ( lhs) ) ;
40
- line. push ( italic (
41
- cmd. get_subcommand_value_name ( )
42
- . unwrap_or_else ( || subcommand_heading ( cmd) )
43
- . to_lowercase ( ) ,
33
+ let flatten = cmd. is_flatten_help_set ( ) ;
34
+
35
+ let mut ord_v = Vec :: new ( ) ;
36
+ if flatten {
37
+ for subcommand in cmd. get_subcommands ( ) {
38
+ ord_v. push ( (
39
+ subcommand. get_display_order ( ) ,
40
+ subcommand. get_bin_name ( ) . unwrap_or_else ( || cmd. get_name ( ) ) ,
41
+ subcommand,
42
+ ) ) ;
43
+ }
44
+ ord_v. sort_by ( |a, b| ( a. 0 , & a. 1 ) . cmp ( & ( b. 0 , & b. 1 ) ) ) ;
45
+ } else {
46
+ ord_v. push ( (
47
+ cmd. get_display_order ( ) ,
48
+ cmd. get_bin_name ( ) . unwrap_or_else ( || cmd. get_name ( ) ) ,
49
+ cmd,
44
50
) ) ;
45
- line. push ( roman ( rhs) ) ;
46
51
}
47
- roff. text ( line) ;
52
+
53
+ let mut first = true ;
54
+ for ( _, name, cmd) in ord_v {
55
+ if !first && flatten {
56
+ roff. control ( "br" , [ ] ) ;
57
+ } else {
58
+ first = false ;
59
+ }
60
+ let mut line = usage ( cmd, name) ;
61
+
62
+ if cmd. has_subcommands ( ) && !flatten {
63
+ let ( lhs, rhs) = subcommand_markers ( cmd) ;
64
+ line. push ( roman ( lhs) ) ;
65
+ line. push ( italic (
66
+ cmd. get_subcommand_value_name ( )
67
+ . unwrap_or_else ( || subcommand_heading ( cmd) )
68
+ . to_lowercase ( ) ,
69
+ ) ) ;
70
+ line. push ( roman ( rhs) ) ;
71
+ }
72
+ roff. text ( line) ;
48
73
}
49
74
}
50
75
@@ -226,6 +251,26 @@ pub(crate) fn subcommands(roff: &mut Roff, cmd: &clap::Command, section: &str) {
226
251
}
227
252
}
228
253
254
+ pub ( crate ) fn flat_subcommands ( roff : & mut Roff , cmd : & clap:: Command ) {
255
+ for sub in cmd. get_subcommands ( ) . filter ( |s| !s. is_hide_set ( ) ) {
256
+ roff. control ( "TP" , [ ] ) ;
257
+
258
+ let mut line = usage ( sub, sub. get_name ( ) ) ;
259
+
260
+ if let Some ( about) = sub. get_long_about ( ) . or_else ( || sub. get_about ( ) ) {
261
+ line. push ( roman ( "\n " ) ) ;
262
+ line. push ( roman ( about. to_string ( ) ) ) ;
263
+ }
264
+
265
+ if let Some ( after_help) = sub. get_after_help ( ) {
266
+ line. push ( roman ( "\n " ) ) ;
267
+ line. push ( roman ( after_help. to_string ( ) ) ) ;
268
+ }
269
+
270
+ roff. text ( line) ;
271
+ }
272
+ }
273
+
229
274
pub ( crate ) fn version ( cmd : & clap:: Command ) -> String {
230
275
format ! (
231
276
"v{}" ,
0 commit comments