@@ -29,10 +29,8 @@ pub(crate) fn description(roff: &mut Roff, cmd: &clap::Command) {
2929 }
3030}
3131
32- pub ( crate ) fn synopsis ( roff : & mut Roff , cmd : & clap:: Command ) {
33- let name = cmd. get_bin_name ( ) . unwrap_or_else ( || cmd. get_name ( ) ) ;
32+ pub ( crate ) fn command_with_args ( cmd : & clap:: Command , name : String ) -> Vec < Inline > {
3433 let mut line = vec ! [ bold( name) , roman( " " ) ] ;
35-
3634 for opt in cmd. get_arguments ( ) . filter ( |i| !i. is_hide_set ( ) ) {
3735 let ( lhs, rhs) = option_markers ( opt) ;
3836 match ( opt. get_short ( ) , opt. get_long ( ) ) {
@@ -74,18 +72,46 @@ pub(crate) fn synopsis(roff: &mut Roff, cmd: &clap::Command) {
7472 line. push ( roman ( " " ) ) ;
7573 }
7674
77- if cmd. has_subcommands ( ) {
78- let ( lhs, rhs) = subcommand_markers ( cmd) ;
79- line. push ( roman ( lhs) ) ;
80- line. push ( italic (
81- cmd. get_subcommand_value_name ( )
82- . unwrap_or_else ( || subcommand_heading ( cmd) )
83- . to_lowercase ( ) ,
84- ) ) ;
85- line. push ( roman ( rhs) ) ;
75+ line
76+ }
77+
78+ pub ( crate ) fn synopsis ( roff : & mut Roff , cmd : & clap:: Command ) {
79+ let name = cmd. get_bin_name ( ) . unwrap_or_else ( || cmd. get_name ( ) ) ;
80+ let flatten = cmd. is_flatten_help_set ( ) ;
81+
82+ let mut ord_v = Vec :: new ( ) ;
83+ if flatten {
84+ for subcommand in cmd. get_subcommands ( ) {
85+ ord_v. push ( (
86+ subcommand. get_display_order ( ) ,
87+ format ! ( "{} {}" , name, subcommand. get_name( ) . to_owned( ) ) ,
88+ subcommand,
89+ ) ) ;
90+ }
91+ ord_v. sort_by ( |a, b| ( a. 0 , & a. 1 ) . cmp ( & ( b. 0 , & b. 1 ) ) ) ;
92+ } else {
93+ ord_v. push ( ( cmd. get_display_order ( ) , name. to_string ( ) , cmd) )
8694 }
8795
88- roff. text ( line) ;
96+ for ( _, name, cmd) in ord_v {
97+ let mut line = command_with_args ( cmd, name) ;
98+
99+ if cmd. has_subcommands ( ) && !flatten {
100+ let ( lhs, rhs) = subcommand_markers ( cmd) ;
101+ line. push ( roman ( lhs) ) ;
102+ line. push ( italic (
103+ cmd. get_subcommand_value_name ( )
104+ . unwrap_or_else ( || subcommand_heading ( cmd) )
105+ . to_lowercase ( ) ,
106+ ) ) ;
107+ line. push ( roman ( rhs) ) ;
108+ }
109+ roff. text ( line) ;
110+
111+ if flatten {
112+ roff. control ( "br" , [ ] ) ;
113+ }
114+ }
89115}
90116
91117pub ( crate ) fn options ( roff : & mut Roff , cmd : & clap:: Command ) {
@@ -220,6 +246,28 @@ pub(crate) fn subcommands(roff: &mut Roff, cmd: &clap::Command, section: &str) {
220246 }
221247}
222248
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 name = sub. get_name ( ) . to_string ( ) ;
254+
255+ let mut line = command_with_args ( sub, name) ;
256+
257+ if let Some ( about) = sub. get_long_about ( ) . or_else ( || sub. get_about ( ) ) {
258+ line. push ( roman ( "\n " ) ) ;
259+ line. push ( roman ( about. to_string ( ) ) ) ;
260+ }
261+
262+ if let Some ( after_help) = sub. get_after_help ( ) {
263+ line. push ( roman ( "\n " ) ) ;
264+ line. push ( roman ( after_help. to_string ( ) ) ) ;
265+ }
266+
267+ roff. text ( line) ;
268+ }
269+ }
270+
223271pub ( crate ) fn version ( cmd : & clap:: Command ) -> String {
224272 format ! (
225273 "v{}" ,
0 commit comments