diff options
author | Nora Widdecke <nora@sequoia-pgp.org> | 2022-07-14 10:17:23 +0200 |
---|---|---|
committer | Nora Widdecke <nora@sequoia-pgp.org> | 2022-07-14 10:29:38 +0200 |
commit | a7b3be70931d2493501db7abfc7cc90da1338851 (patch) | |
tree | 9467fc5ddd63643790a0e234b770bdc65a6bb9f1 | |
parent | f8dfcef6ae4a03d733328cdfe4b3f2c5a8f3d626 (diff) |
sq: add see_also to manpagesnora/clap3-man
-rw-r--r-- | Cargo.lock | 20 | ||||
-rw-r--r-- | Cargo.toml | 6 | ||||
-rw-r--r-- | sq/build.rs | 60 |
3 files changed, 63 insertions, 23 deletions
@@ -422,9 +422,8 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190814073e85d238f31ff738fcb0bf6910cedeb73376c87cd69291028966fd83" +version = "3.2.10" +source = "git+https://gitlab.com/sequoia-pgp/clap?branch=for_sequoia#904ae174f6bc61494d07a68bf57d16794a981b6b" dependencies = [ "atty", "bitflags", @@ -444,14 +443,13 @@ version = "3.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da92e6facd8d73c22745a5d3cbb59bdf8e46e3235c923e516527d8e81eec14a4" dependencies = [ - "clap 3.2.8", + "clap 3.2.10", ] [[package]] name = "clap_derive" version = "3.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "759bf187376e1afa7b85b959e6a664a3e7a95203415dba952ad19139e798f902" +source = "git+https://gitlab.com/sequoia-pgp/clap?branch=for_sequoia#904ae174f6bc61494d07a68bf57d16794a981b6b" dependencies = [ "heck 0.4.0", "proc-macro-error", @@ -463,8 +461,7 @@ dependencies = [ [[package]] name = "clap_lex" version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +source = "git+https://gitlab.com/sequoia-pgp/clap?branch=for_sequoia#904ae174f6bc61494d07a68bf57d16794a981b6b" dependencies = [ "os_str_bytes", ] @@ -472,10 +469,9 @@ dependencies = [ [[package]] name = "clap_mangen" version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "937efe4451c32be4ccb3e19549cbb1ea5cb85197f39b87a9662ca1d7b1765d1d" +source = "git+https://gitlab.com/sequoia-pgp/clap?branch=for_sequoia#904ae174f6bc61494d07a68bf57d16794a981b6b" dependencies = [ - "clap 3.2.8", + "clap 3.2.10", "roff", ] @@ -2716,7 +2712,7 @@ dependencies = [ "buffered-reader", "cfg-if", "chrono", - "clap 3.2.8", + "clap 3.2.10", "clap_complete", "clap_mangen", "fehler", @@ -11,3 +11,9 @@ members = [ [profile.release] debug = true + +[patch.crates-io] +#clap = { path = "../clap" } +#clap_mangen = { path = "../clap/clap_mangen" } +clap = { git = "https://gitlab.com/sequoia-pgp/clap", branch = "for_sequoia" } +clap_mangen = { git = "https://gitlab.com/sequoia-pgp/clap", branch = "for_sequoia" } diff --git a/sq/build.rs b/sq/build.rs index e375981f..158cdcc1 100644 --- a/sq/build.rs +++ b/sq/build.rs @@ -5,6 +5,7 @@ use std::io::{self, Write}; use std::path::{Path, PathBuf}; use clap_complete::Shell; use anyhow::Result; +use clap_mangen::Man; pub mod sq_cli { include!("src/sq_cli.rs"); @@ -32,7 +33,11 @@ fn main() { writeln!(main, "\ninclude!(\"sq.rs\");").unwrap(); fs::create_dir_all("manpages").unwrap(); - let _ = dump_manpage(&sq, std::ffi::OsStr::new("manpages"), None); + let _ = dump_manpage( + &sq, + std::ffi::OsStr::new("manpages"), + Vec::from([sq.get_name().to_owned()]), + ); // TODO: CARGO_TARGET_DIR is not always set, I think currently only by Makefile. So this is // janky @@ -112,31 +117,64 @@ fn dump_help(sink: &mut dyn io::Write, Ok(()) } -fn dump_manpage(cmd: &clap::Command, outdir: &OsStr, prefix: Option<&str>) -> Result<()> { - let command_name = match prefix { - Some(p) => p.to_owned() + "-" + cmd.get_name(), - None => cmd.get_name().to_owned(), - }; - - let man = clap_mangen::Man::new(cmd.clone().name(&command_name)) +fn dump_manpage( + cmd: &clap::Command, + outdir: &OsStr, + up_to_same_level: Vec<String>, +) -> Result<()> { + //let command_name = match prefix { + // Some(p) => p.to_owned() + "-" + cmd.get_name(), + // None => cmd.get_name().to_owned(), + //}; + + // add subcommands to see_also + let mut see_also = up_to_same_level.clone(); + see_also.extend( + cmd.get_subcommands() + .map(|sc| sc.get_display_name().unwrap_or_else(|| sc.get_name())) + .map(|s| s.to_owned()) + ); + + let mut man = clap_mangen::Man::new(cmd.clone()) // Add build date in the form "Month Year" to the bottom of the manpage .date(chrono::Utc::today().format("%B %Y").to_string()) // The manual's title, akin to git's "Git Manual" .manual("Sequoia Manual") // The source for all (sub)commands is sq, with version .source(&format!("sq {}", env!("CARGO_PKG_VERSION"))); + + man = add_relevant_see_also( + man, + see_also.clone(), + cmd.get_display_name().unwrap_or_else(|| cmd.get_name()), + ); let mut buffer: Vec<u8> = Default::default(); man.render(&mut buffer)?; let mut path = PathBuf::from(outdir); - path.push(&command_name); + path.push(cmd.get_display_name().unwrap_or_else(|| cmd.get_name())); path.set_extension("1"); println!("cargo:warning=generated manpages: {:?}", path); std::fs::write(path, buffer)?; - for subcmd in cmd.get_subcommands() { - dump_manpage(subcmd, outdir, Some(&command_name))? + for subcmd in cmd.get_subcommands().filter(|s| !s.get_name().contains("help")) { + dump_manpage(subcmd, outdir, see_also.clone())? } Ok(()) } + +fn add_relevant_see_also<'a>( + mut man: Man<'a>, + subcommands: Vec<String>, + own_name: &str, +) -> Man<'a> { + for s in subcommands + .into_iter() + .filter(|sc| sc != &own_name) + .filter(|sc| !sc.contains("help")) + { + man = man.see_also(format!("{}(1)", s)); + } + man +} |