Skip to content

Commit

Permalink
cli: Use clap-mangen to generate man pages
Browse files Browse the repository at this point in the history
  • Loading branch information
felinira committed Jul 25, 2024
1 parent bc997d8 commit fee1608
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 49 deletions.
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"]
24 changes: 22 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -249,7 +256,7 @@ struct WormholeCli {
display_order = 100
)]
log: bool,
#[clap(subcommand)]
#[command(subcommand)]
command: WormholeCommand,
}

Expand Down Expand Up @@ -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(())
Expand Down
47 changes: 0 additions & 47 deletions wormhole.1

This file was deleted.

0 comments on commit fee1608

Please sign in to comment.