From fee1608814d2373290f662a5753b9b216ae6ede0 Mon Sep 17 00:00:00 2001 From: Fina Wilke Date: Thu, 25 Jul 2024 22:48:06 +0200 Subject: [PATCH] cli: Use clap-mangen to generate man pages --- Cargo.lock | 17 +++++++++++++++++ cli/Cargo.toml | 2 ++ cli/src/main.rs | 24 ++++++++++++++++++++++-- wormhole.1 | 47 ----------------------------------------------- 4 files changed, 41 insertions(+), 49 deletions(-) delete mode 100644 wormhole.1 diff --git a/Cargo.lock b/Cargo.lock index ac947c9b..7469f502 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -637,6 +637,16 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" +[[package]] +name = "clap_mangen" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f17415fd4dfbea46e3274fcd8d368284519b358654772afb700dc2e8d2b24eeb" +dependencies = [ + "clap", + "roff", +] + [[package]] name = "clipboard-win" version = "5.4.0" @@ -1719,6 +1729,7 @@ dependencies = [ "async-std", "clap", "clap_complete", + "clap_mangen", "color-eyre", "console", "ctrlc", @@ -2437,6 +2448,12 @@ dependencies = [ "serde", ] +[[package]] +name = "roff" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88f8660c1ff60292143c98d08fc6e2f654d722db50410e3f3797d40baaf9d8f3" + [[package]] name = "rustc-demangle" version = "0.1.24" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 2d6cc8dc..2471fce5 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -29,6 +29,7 @@ rand = "0.8.3" # CLI specific dependencies magic-wormhole = { path = "..", version = "0.7", features = ["all"] } +clap_mangen = { version = "0.2", optional = true } clap = { version = "4", features = ["cargo", "derive", "help"] } clap_complete = "4" env_logger = "0.11" @@ -57,3 +58,4 @@ experimental = ["experimental-transfer-v2"] default = ["magic-wormhole/default", "magic-wormhole/forwarding"] all = ["default", "magic-wormhole/native-tls"] +generate-manpage = ["dep:clap_mangen"] diff --git a/cli/src/main.rs b/cli/src/main.rs index 283ed3f7..8b71b705 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -225,12 +225,19 @@ enum WormholeCommand { }, #[command(hide = true)] Help, + /// Generate the manual pages for this project + #[cfg(feature = "generate-manpage")] + #[command(name = "generate-manpage", hide = true)] + GenerateManpage { + /// The path of the manpage + path: PathBuf, + }, } #[derive(Debug, Parser)] #[command( version, - author, + author = "The wormhole-rs developers", about, arg_required_else_help = true, disable_help_subcommand = true, @@ -249,7 +256,7 @@ struct WormholeCli { display_order = 100 )] log: bool, - #[clap(subcommand)] + #[command(subcommand)] command: WormholeCommand, } @@ -546,6 +553,19 @@ async fn main() -> eyre::Result<()> { println!("Use --help to get help"); std::process::exit(2); }, + #[cfg(feature = "generate-manpage")] + WormholeCommand::GenerateManpage { path } => { + println!("Generating manpage as {}", path.canonicalize()?.display()); + + let cmd = WormholeCli::command(); + let man = clap_mangen::Man::new(cmd) + .section("1") + .date("Jul 2024") + .manual("User Commands"); + + let mut file = std::fs::File::create(path)?; + man.render(&mut file)?; + }, } Ok(()) diff --git a/wormhole.1 b/wormhole.1 deleted file mode 100644 index 46ef0a90..00000000 --- a/wormhole.1 +++ /dev/null @@ -1,47 +0,0 @@ -.TH WORMHOLE-RS "1" "May 2024" "wormhole-rs 0.6.1" "User Commands" -.SH NAME -wormhole-rs \- manual page for wormhole-rs 0.6.1 -.SH DESCRIPTION -wormhole\-rs 0.6.1 -.SS "USAGE:" -.IP -wormhole\-rs [OPTIONS] -.SS "OPTIONS:" -.TP -\fB\-h\fR, \fB\-\-help\fR -Print this help message -.TP -\fB\-v\fR, \fB\-\-verbose\fR -Enable logging to stdout, for debugging purposes -.TP -\fB\-V\fR, \fB\-\-version\fR -Print version information -.SS "SUBCOMMANDS:" -.TP -forward -Forward ports from one machine to another -.TP -receive -Receive a file or a folder [aliases: rx] -.TP -send -Send a file or a folder [aliases: tx] -.TP -send\-many -Send a file to many recipients. READ HELP PAGE FIRST! -.PP -Run a subcommand with `\-\-help` to know how it's used. -To send files, use `wormhole send `. -To receive files, use `wormhole receive `. -.SH AUTHOR -.TP -Matthias Geiger -.SH COPYRIGHT -.PP -Copyright \[co] 2024 Matthias Geiger -.PP -This manual page was written for the Debian system (and may be used by -others). -.PP -Permission is granted to copy, distribute and/or modify this document -under the terms of the EUPL 1.2, or, at your option, any later version.