Skip to content

Commit d54c53b

Browse files
committed
cli: Use clap-mangen to generate man pages
1 parent 00c3ef9 commit d54c53b

File tree

4 files changed

+69
-37
lines changed

4 files changed

+69
-37
lines changed

Cargo.lock

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ rand = "0.8.3"
1515

1616
# CLI specific dependencies
1717
magic-wormhole = { path = "..", features = ["all"] }
18+
clap_mangen = { version = "0.2", optional = true }
1819
clap = { version = "4", features = ["cargo", "derive", "help"] }
1920
clap_complete = "4"
2021
env_logger = "0.11"
@@ -31,3 +32,6 @@ arboard = { version = "3.2.0", features = [
3132

3233
[dev-dependencies]
3334
trycmd = "0.15"
35+
36+
[features]
37+
generate-manpage = ["dep:clap_mangen"]

cli/src/main.rs

+22-2
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,19 @@ enum WormholeCommand {
221221
},
222222
#[command(hide = true)]
223223
Help,
224+
/// Generate the manual pages for this project
225+
#[cfg(feature = "generate-manpage")]
226+
#[command(name = "generate-manpage", hide = true)]
227+
GenerateManpage {
228+
/// The path of the manpage
229+
path: PathBuf,
230+
},
224231
}
225232

226233
#[derive(Debug, Parser)]
227234
#[command(
228235
version,
229-
author,
236+
author = "The wormhole-rs developers",
230237
about,
231238
arg_required_else_help = true,
232239
disable_help_subcommand = true,
@@ -245,7 +252,7 @@ struct WormholeCli {
245252
display_order = 100
246253
)]
247254
log: bool,
248-
#[clap(subcommand)]
255+
#[command(subcommand)]
249256
command: WormholeCommand,
250257
}
251258

@@ -542,6 +549,19 @@ async fn main() -> eyre::Result<()> {
542549
println!("Use --help to get help");
543550
std::process::exit(2);
544551
},
552+
#[cfg(feature = "generate-manpage")]
553+
WormholeCommand::GenerateManpage { path } => {
554+
println!("Generating manpage as {}", path.canonicalize()?.display());
555+
556+
let cmd = WormholeCli::command();
557+
let man = clap_mangen::Man::new(cmd)
558+
.section("1")
559+
.date("Jul 2024")
560+
.manual("User Commands");
561+
562+
let mut file = std::fs::File::create(path)?;
563+
man.render(&mut file)?;
564+
},
545565
}
546566

547567
Ok(())

wormhole.1

+26-35
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,39 @@
1-
.TH WORMHOLE-RS "1" "May 2024" "wormhole-rs 0.6.1" "User Commands"
1+
.ie \n(.g .ds Aq \(aq
2+
.el .ds Aq '
3+
.TH wormhole-rs 1 "Jul 2024" "wormhole-rs 0.6.1" "User Commands"
24
.SH NAME
3-
wormhole-rs \- manual page for wormhole-rs 0.6.1
5+
wormhole\-rs
6+
.SH SYNOPSIS
7+
\fBwormhole\-rs\fR [\fB\-v\fR|\fB\-\-verbose\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] <\fIsubcommands\fR>
48
.SH DESCRIPTION
5-
wormhole\-rs 0.6.1
6-
.SS "USAGE:"
7-
.IP
8-
wormhole\-rs [OPTIONS] <SUBCOMMAND>
9-
.SS "OPTIONS:"
10-
.TP
11-
\fB\-h\fR, \fB\-\-help\fR
12-
Print this help message
9+
.SH OPTIONS
1310
.TP
1411
\fB\-v\fR, \fB\-\-verbose\fR
1512
Enable logging to stdout, for debugging purposes
1613
.TP
14+
\fB\-h\fR, \fB\-\-help\fR
15+
Print help
16+
.TP
1717
\fB\-V\fR, \fB\-\-version\fR
18-
Print version information
19-
.SS "SUBCOMMANDS:"
18+
Print version
19+
.SH SUBCOMMANDS
2020
.TP
21-
forward
22-
Forward ports from one machine to another
21+
wormhole\-rs\-send(1)
22+
Send a file or a folder
2323
.TP
24-
receive
25-
Receive a file or a folder [aliases: rx]
24+
wormhole\-rs\-receive(1)
25+
Receive a file or a folder
2626
.TP
27-
send
28-
Send a file or a folder [aliases: tx]
27+
wormhole\-rs\-send\-many(1)
28+
Send a file to many recipients
2929
.TP
30-
send\-many
31-
Send a file to many recipients. READ HELP PAGE FIRST!
32-
.PP
33-
Run a subcommand with `\-\-help` to know how it's used.
30+
wormhole\-rs\-forward(1)
31+
Forward ports from one machine to another
32+
.SH EXTRA
33+
Run a subcommand with `\-\-help` to know how it\*(Aqs used.
3434
To send files, use `wormhole send <PATH>`.
3535
To receive files, use `wormhole receive <CODE>`.
36-
.SH AUTHOR
37-
.TP
38-
Matthias Geiger <[email protected]>
39-
.SH COPYRIGHT
40-
.PP
41-
Copyright \[co] 2024 Matthias Geiger
42-
.PP
43-
This manual page was written for the Debian system (and may be used by
44-
others).
45-
.PP
46-
Permission is granted to copy, distribute and/or modify this document
47-
under the terms of the GNU General Public License, Version 3 or (at your
48-
option) any later version published by the Free Software Foundation.
36+
.SH VERSION
37+
v0.6.1
38+
.SH AUTHORS
39+
The wormhole\-rs developers

0 commit comments

Comments
 (0)