-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.rs
53 lines (43 loc) · 1.28 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
52
53
use clap::CommandFactory;
use clap_mangen::Man;
use project_root::get_project_root;
use std::fs::File;
use std::io::Error;
use std::path::{Path, PathBuf};
use std::process::exit;
include!("src/cli.rs");
fn build_man(out_dir: &Path) -> Result<(), Error> {
let app = WhammCli::command();
let file = Path::new(&out_dir).join("example.1");
let mut file = File::create(file)?;
Man::new(app).render(&mut file)?;
Ok(())
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo:rerun-if-changed=src/cli.rs");
println!("cargo:rerun-if-changed=man");
// Create `target/assets/` folder.
let mut path = match get_pb(&PathBuf::from("target")) {
Ok(pb) => pb,
Err(_) => exit(1),
};
path.push("assets");
std::fs::create_dir_all(&path).unwrap();
// build_shell_completion(&path)?;
build_man(&path)?;
Ok(())
}
fn get_pb(file_pb: &PathBuf) -> Result<PathBuf, String> {
if file_pb.is_relative() {
match get_project_root() {
Ok(r) => {
let mut full_path = r.clone();
full_path.push(file_pb);
Ok(full_path)
}
Err(e) => Err(format!("the root folder does not exist: {:?}", e)),
}
} else {
Ok(file_pb.clone())
}
}