Skip to content

Commit ae6b848

Browse files
committed
refactor(man): write files directly in generate subcommand
The generate subcommand now writes to exports/ files directly instead of printing to stdout, so the shell script no longer needs redirections. https://claude.ai/code/session_01CrXuWDMVQsiUBoy6ceACsF
1 parent cf9c581 commit ae6b848

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

cli/man_page.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use clap::{Parser, ValueEnum};
22
use parallel_disk_usage::man_page::render_man_page;
3-
use std::process::{Command, ExitCode};
3+
use std::{
4+
fs,
5+
process::{Command, ExitCode},
6+
};
47

58
const LINE_LENGTH: &str = "120";
69

@@ -86,8 +89,18 @@ fn normalize_text(text: &str) -> String {
8689
result
8790
}
8891

92+
fn write_file(path: &str, content: &str) -> ExitCode {
93+
match fs::write(path, content) {
94+
Ok(()) => ExitCode::SUCCESS,
95+
Err(error) => {
96+
eprintln!("error writing {path}: {error}");
97+
ExitCode::FAILURE
98+
}
99+
}
100+
}
101+
89102
fn check_file(path: &str, expected: &str) -> ExitCode {
90-
match std::fs::read_to_string(path) {
103+
match fs::read_to_string(path) {
91104
Ok(actual) if actual == expected => ExitCode::SUCCESS,
92105
Ok(_) => {
93106
eprintln!("{path} is outdated, run ./generate-completions.sh to update it");
@@ -104,15 +117,9 @@ fn main() -> ExitCode {
104117
let args = Args::parse();
105118
let page_num = args.page.number();
106119
match (args.action, args.kind) {
107-
(Action::Generate, Kind::Roff) => {
108-
print!("{}", render_man_page());
109-
ExitCode::SUCCESS
110-
}
120+
(Action::Generate, Kind::Roff) => write_file(&roff_path(page_num), &render_man_page()),
111121
(Action::Generate, Kind::Man) => match render_man_output(page_num) {
112-
Ok(content) => {
113-
print!("{content}");
114-
ExitCode::SUCCESS
115-
}
122+
Ok(content) => write_file(&man_path(page_num), &content),
116123
Err(error) => {
117124
eprintln!("error: {error}");
118125
ExitCode::FAILURE

generate-completions.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ gen elvish completion.elv
1717
./run.sh pdu --help | sed 's/[[:space:]]*$//' > exports/long.help
1818
./run.sh pdu -h | sed 's/[[:space:]]*$//' > exports/short.help
1919
./run.sh pdu-usage-md > USAGE.md
20-
./run.sh pdu-man-page generate roff 1 > exports/pdu.1
21-
./run.sh pdu-man-page generate man 1 > exports/pdu.1.man
20+
./run.sh pdu-man-page generate roff 1
21+
./run.sh pdu-man-page generate man 1

0 commit comments

Comments
 (0)