Skip to content

Commit

Permalink
feat(man): add man page generation script (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Apr 14, 2022
1 parent fa2639a commit 03d55c8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
25 changes: 21 additions & 4 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions git-cliff/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ edition = "2021"
name = "git-cliff-completions"
path = "src/bin/completions.rs"

[[bin]]
name = "git-cliff-mangen"
path = "src/bin/mangen.rs"

[features]
# check for new versions
default = ["update-informer"]
Expand All @@ -25,6 +29,7 @@ pretty_env_logger = "0.4.0"
log = "0.4.14"
dirs-next = "2.0.0"
clap_complete = "3.1.1"
clap_mangen = "0.1.2"

[dependencies.git-cliff-core]
version = "0.6.1" # managed by release.sh
Expand Down
24 changes: 24 additions & 0 deletions git-cliff/src/bin/mangen.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use clap::CommandFactory;
use clap_mangen::Man;
use git_cliff::args::Opt;
use std::env;
use std::fs;
use std::io::Result;
use std::path::PathBuf;

/// Man page can be created with:
/// `cargo run --bin git-cliff-mangen`
/// in a directory specified by the environment variable OUT_DIR.
/// See <https://doc.rust-lang.org/cargo/reference/environment-variables.html>
fn main() -> Result<()> {
let out_dir = env::var("OUT_DIR").expect("OUT_DIR is not set");
let out_path =
PathBuf::from(out_dir).join(format!("{}.1", env!("CARGO_PKG_NAME")));
let app = Opt::command();
let man = Man::new(app);
let mut buffer = Vec::<u8>::new();
man.render(&mut buffer)?;
fs::write(&out_path, buffer)?;
println!("Man page is generated at {:?}", out_path);
Ok(())
}

0 comments on commit 03d55c8

Please sign in to comment.