-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.rs
51 lines (39 loc) · 1.38 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! This script auto-generates a man page from the CLI configuration.
use bpaf::doc::Section;
use time::OffsetDateTime;
// We're reusing the module just for the Cli struct. Ignore the rest of the code
// and don't report it as "never used" in this build script.
#[allow(dead_code)]
#[path = "src/cli.rs"]
mod cli;
// Man page metadata
const CARGO_PKG_NAME: &str = env!("CARGO_PKG_NAME");
const SECTION: Section = Section::General;
const CARGO_PKG_AUTHORS: &str = env!("CARGO_PKG_AUTHORS");
//const CARGO_PKG_REPOSITORY: &str = env!("CARGO_PKG_REPOSITORY");
//const CARGO_PKG_HOMEPAGE: &str = env!("CARGO_PKG_HOMEPAGE");
fn main() -> std::io::Result<()> {
let out_dir =
std::path::PathBuf::from(std::env::var_os("OUT_DIR").ok_or(std::io::ErrorKind::NotFound)?);
let date = current_date();
let parser = cli::cli();
let man_page = parser.render_manpage(
CARGO_PKG_NAME,
SECTION,
Some(&date),
Some(CARGO_PKG_AUTHORS),
None,
);
let man_name = format!("{CARGO_PKG_NAME}.1");
let man_path = out_dir.join(man_name);
std::fs::write(man_path, man_page)?;
Ok(())
}
/// Generate the current date to mark the last update of the man page.
/// The format is "Month Year".
fn current_date() -> String {
let now = OffsetDateTime::now_utc();
let month = now.month();
let year = now.year();
format!("{month} {year}")
}