Skip to content

Commit 35dbf94

Browse files
committed
refactor(man): rename EXTRA section to EXAMPLES and extract render function
Move man page rendering into a shared `src/man_page.rs` module (gated on `cli-man` feature) so both the binary and sync test use the same logic. Replace the `.SH EXTRA` section header with `.SH EXAMPLES` in the generated output. https://claude.ai/code/session_01CrXuWDMVQsiUBoy6ceACsF
1 parent 4036c8f commit 35dbf94

6 files changed

Lines changed: 28 additions & 19 deletions

File tree

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ zero-copy-pads = "0.2.0"
9292

9393
[dev-dependencies]
9494
build-fs-tree = "0.8.1"
95-
clap_mangen = "0.2.27"
9695
command-extra = "1.0.0"
9796
libc = "0.2.182"
9897
maplit = "1.0.2"

cli/man_page.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
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

64
fn 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

exports/pdu.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Print version
9898
.TP
9999
[\fIFILES\fR]
100100
List of files and/or directories
101-
.SH EXTRA
101+
.SH EXAMPLES
102102
Examples:
103103
Show disk usage chart of current working directory
104104
$ pdu

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ pub use serde_json;
1414
pub mod app;
1515
#[cfg(feature = "cli")]
1616
pub mod args;
17+
#[cfg(feature = "cli-man")]
18+
pub mod man_page;
1719
#[cfg(feature = "cli")]
1820
pub mod runtime_error;
1921
#[cfg(feature = "cli")]

src/man_page.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
}

tests/sync_man_page.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,13 @@
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]
1513
fn 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,

0 commit comments

Comments
 (0)