-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
40 lines (29 loc) · 885 Bytes
/
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
// SPDX-License-Identifier: Apache-2.0
#[path = "src/cli.rs"]
mod cli;
use std::{
env::var_os,
fs::{create_dir_all, File},
io::{self, Write},
path::Path,
};
use clap::CommandFactory;
use clap_complete::{generate_to, shells::Shell};
use clap_mangen::Man;
use crate::cli::Args;
fn main() -> io::Result<()> {
let asset_dir = Path::new(
&var_os("CARGO_MANIFEST_DIR").expect("Environment `CARGO_MANIFEST_DIR` not set by cargo."),
)
.join("target/assets");
create_dir_all(&asset_dir)?;
let mut cmd = Args::command();
for shell in [Shell::Bash, Shell::Fish, Shell::Zsh] {
generate_to(shell, &mut cmd, "rsjudge", &asset_dir)?;
}
let mut manpage = File::create(asset_dir.join("rsjudge.1"))?;
Man::new(cmd).render(&mut manpage)?;
manpage.flush()?;
println!("cargo:rerun-if-changed=src/cli.rs");
Ok(())
}