-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.rs
49 lines (43 loc) · 1.39 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
use std::env;
use std::fs::{create_dir_all, read_dir, File, OpenOptions};
use std::path::Path;
use std::process::{exit, Command, Stdio};
use clap::Shell;
#[path = "src/app.rs"]
mod app;
fn main() {
// OUT_DIR is set by Cargo and it's where any additional build artifacts
// are written.
let outdir = match env::var_os("OUT_DIR") {
Some(outdir) => outdir,
None => {
eprintln!("OUT_DIR environment variable not defined. Please file a bug.");
exit(1);
}
};
create_dir_all(&outdir).unwrap();
generate_man_pages(&outdir);
// Use clap to build completion files.
let mut app = app::args();
app.gen_completions(app::NAME, Shell::Bash, &outdir);
app.gen_completions(app::NAME, Shell::Fish, &outdir);
}
fn generate_man_pages<P: AsRef<Path>>(outdir: P) {
for page in read_dir("man").unwrap() {
let in_path = page.unwrap().path();
let out_path = outdir.as_ref().join(in_path.file_stem().unwrap());
let input = File::open(in_path).unwrap();
let output = OpenOptions::new()
.write(true)
.create(true)
.open(out_path)
.unwrap();
let mut scdoc = Command::new("scdoc")
.stdin(Stdio::from(input))
.stdout(output)
.stderr(Stdio::inherit())
.spawn()
.unwrap();
scdoc.wait().unwrap();
}
}