@@ -30,21 +30,41 @@ 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) ;
33
+ if cmd. is_flatten_help_set ( ) {
34
+ let mut ord_v = Vec :: new ( ) ;
35
+ let mut first = true ;
36
+
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 ) ) ) ;
36
45
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 ( ) ,
44
- ) ) ;
45
- line. push ( roman ( rhs) ) ;
46
- }
47
- roff. text ( line) ;
46
+ for ( _, name, cmd) in ord_v {
47
+ if !first {
48
+ roff. control ( "br" , [ ] ) ;
49
+ } else {
50
+ first = false ;
51
+ }
52
+ roff. text ( usage ( cmd, name) ) ;
53
+ }
54
+ } else {
55
+ let mut line = usage ( cmd, cmd. get_bin_name ( ) . unwrap_or_else ( || cmd. get_name ( ) ) ) ;
56
+
57
+ if cmd. has_subcommands ( ) {
58
+ let ( lhs, rhs) = subcommand_markers ( cmd) ;
59
+ line. push ( roman ( lhs) ) ;
60
+ line. push ( italic (
61
+ cmd. get_subcommand_value_name ( )
62
+ . unwrap_or_else ( || subcommand_heading ( cmd) )
63
+ . to_lowercase ( ) ,
64
+ ) ) ;
65
+ line. push ( roman ( rhs) ) ;
66
+ }
67
+ roff. text ( line) ;
48
68
}
49
69
}
50
70
@@ -226,6 +246,26 @@ pub(crate) fn subcommands(roff: &mut Roff, cmd: &clap::Command, section: &str) {
226
246
}
227
247
}
228
248
249
+ pub ( crate ) fn flat_subcommands ( roff : & mut Roff , cmd : & clap:: Command ) {
250
+ for sub in cmd. get_subcommands ( ) . filter ( |s| !s. is_hide_set ( ) ) {
251
+ roff. control ( "TP" , [ ] ) ;
252
+
253
+ let mut line = usage ( sub, sub. get_name ( ) ) ;
254
+
255
+ if let Some ( about) = sub. get_long_about ( ) . or_else ( || sub. get_about ( ) ) {
256
+ line. push ( roman ( "\n " ) ) ;
257
+ line. push ( roman ( about. to_string ( ) ) ) ;
258
+ }
259
+
260
+ if let Some ( after_help) = sub. get_after_help ( ) {
261
+ line. push ( roman ( "\n " ) ) ;
262
+ line. push ( roman ( after_help. to_string ( ) ) ) ;
263
+ }
264
+
265
+ roff. text ( line) ;
266
+ }
267
+ }
268
+
229
269
pub ( crate ) fn version ( cmd : & clap:: Command ) -> String {
230
270
format ! (
231
271
"v{}" ,
0 commit comments