File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -92,7 +92,6 @@ zero-copy-pads = "0.2.0"
9292
9393[dev-dependencies ]
9494build-fs-tree = " 0.8.1"
95- clap_mangen = " 0.2.27"
9695command-extra = " 1.0.0"
9796libc = " 0.2.182"
9897maplit = " 1.0.2"
Original file line number Diff line number Diff line change 1- use clap:: CommandFactory ;
2- use clap_mangen:: Man ;
3- use parallel_disk_usage:: args:: Args ;
4- use std:: { io:: stdout, process:: ExitCode } ;
1+ use parallel_disk_usage:: man_page:: render_man_page;
2+ use std:: process:: ExitCode ;
53
64fn main ( ) -> ExitCode {
7- let command = Args :: command ( ) ;
8- let man = Man :: new ( command) ;
9- match man. render ( & mut stdout ( ) ) {
10- Ok ( ( ) ) => ExitCode :: SUCCESS ,
5+ match render_man_page ( ) {
6+ Ok ( content) => {
7+ print ! ( "{content}" ) ;
8+ ExitCode :: SUCCESS
9+ }
1110 Err ( error) => {
1211 eprintln ! ( "error: {error}" ) ;
1312 ExitCode :: FAILURE
Original file line number Diff line number Diff line change @@ -98,7 +98,7 @@ Print version
9898.TP
9999[\fI FILES \fR ]
100100List of files and/or directories
101- .SH EXTRA
101+ .SH EXAMPLES
102102Examples:
103103 Show disk usage chart of current working directory
104104 $ pdu
Original file line number Diff line number Diff line change @@ -14,6 +14,8 @@ pub use serde_json;
1414pub mod app;
1515#[ cfg( feature = "cli" ) ]
1616pub mod args;
17+ #[ cfg( feature = "cli-man" ) ]
18+ pub mod man_page;
1719#[ cfg( feature = "cli" ) ]
1820pub mod runtime_error;
1921#[ cfg( feature = "cli" ) ]
Original file line number Diff line number Diff line change 1+ use crate :: args:: Args ;
2+ use clap:: CommandFactory ;
3+ use clap_mangen:: Man ;
4+ use std:: io;
5+
6+ /// Renders the man page for `pdu` as a string.
7+ pub fn render_man_page ( ) -> io:: Result < String > {
8+ let command = Args :: command ( ) ;
9+ let man = Man :: new ( command) ;
10+ let mut buffer = Vec :: new ( ) ;
11+ man. render ( & mut buffer) ?;
12+ let content = String :: from_utf8 ( buffer)
13+ . map_err ( |error| io:: Error :: new ( io:: ErrorKind :: InvalidData , error) ) ?;
14+ Ok ( content. replace ( "\n .SH EXTRA\n " , "\n .SH EXAMPLES\n " ) )
15+ }
Original file line number Diff line number Diff line change 55// Since the CLI in Windows looks a little different, and I am way too lazy to make two versions
66// of man page files, the following test would only run in UNIX-like environment.
77#![ cfg( unix) ]
8- #![ cfg( feature = "cli" ) ]
8+ #![ cfg( feature = "cli-man " ) ]
99
10- use clap:: CommandFactory ;
11- use clap_mangen:: Man ;
12- use parallel_disk_usage:: args:: Args ;
10+ use parallel_disk_usage:: man_page:: render_man_page;
1311
1412#[ test]
1513fn man_page ( ) {
16- let command = Args :: command ( ) ;
17- let man = Man :: new ( command) ;
18- let mut buffer = Vec :: new ( ) ;
19- man. render ( & mut buffer) . expect ( "render man page to buffer" ) ;
20- let received = String :: from_utf8 ( buffer) . expect ( "man page should be valid UTF-8" ) ;
14+ let received = render_man_page ( ) . expect ( "render man page" ) ;
2115 let expected = include_str ! ( "../exports/pdu.1" ) ;
2216 assert ! (
2317 received == expected,
You can’t perform that action at this time.
0 commit comments