summaryrefslogtreecommitdiffstats
path: root/build.rs
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2023-07-15 22:49:24 +0200
committerCanop <cano.petrole@gmail.com>2023-07-15 22:49:24 +0200
commitb8005c8d11cae0206f99d5b62237bd70effa41b8 (patch)
treeae8722d38e4e6db63f9c398de14ca4e8cfe701f6 /build.rs
parent0edc0fc30ae49c39334f783a6b41852ef272c6f0 (diff)
updated man page
Diffstat (limited to 'build.rs')
-rw-r--r--build.rs33
1 files changed, 29 insertions, 4 deletions
diff --git a/build.rs b/build.rs
index b083ad9..ce0a80f 100644
--- a/build.rs
+++ b/build.rs
@@ -1,6 +1,8 @@
-// This file is executed during broot compilation.
-// It builds shell completion scripts.
-
+//! This file is executed during broot compilation.
+//! It builds shell completion scripts and the man page
+//!
+//! Note: to see the eprintln messages, run cargo with
+//! cargo -vv build --release
use {
clap::CommandFactory,
clap_complete::{Generator, Shell},
@@ -12,6 +14,11 @@ use {
include!("src/cli/args.rs");
+/// The man page built by clap-mangen is too rough to be used as is. It's only
+/// used as part of a manual process to update the one in /man/page
+/// so this generation is usually not needed
+pub const BUILD_MAN_PAGE: bool = false;
+
fn write_completions_file<G: Generator + Copy, P: AsRef<OsStr>>(generator: G, out_dir: P) {
let mut args = Args::command();
for name in &["broot", "br"] {
@@ -36,6 +43,24 @@ fn build_completion_scripts() {
eprintln!("completion scripts generated in {out_dir:?}");
}
-fn main() {
+/// generate the man page from the Clap configuration
+fn build_man_page() -> std::io::Result<()> {
+ let out_dir = env::var_os("OUT_DIR").expect("out dir not set");
+ let out_dir = PathBuf::from(out_dir);
+ let cmd = Args::command();
+ let man = clap_mangen::Man::new(cmd);
+ let mut buffer: Vec<u8> = Default::default();
+ man.render(&mut buffer)?;
+ let file_path = out_dir.join("broot.1");
+ std::fs::write(&file_path, buffer)?;
+ eprintln!("map page generated in {file_path:?}");
+ Ok(())
+}
+
+fn main() -> std::io::Result<()> {
build_completion_scripts();
+ if BUILD_MAN_PAGE {
+ build_man_page()?;
+ }
+ Ok(())
}