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