-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.rs
79 lines (70 loc) · 2.19 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
include!("src/cli.rs");
fn main() {
use std::{env::var, fs, str::FromStr};
use structopt::clap::Shell;
let mut app = Options::clap();
let out_dir = var("SHELL_COMPLETIONS_DIR").or(var("OUT_DIR")).unwrap();
fs::create_dir_all(&out_dir).unwrap();
Shell::variants().iter().for_each(|shell| {
app.gen_completions("rep", Shell::from_str(shell).unwrap(), &out_dir);
});
create_man_page();
}
fn create_man_page() {
use man::prelude::*;
let page = Manual::new("rep")
.flag(
Flag::new()
.short("-w")
.long("--write")
.help(
r#"Write the output to files directly (instead of outputting a patch)
If this flag is not present, and a patch is output, then the default pager is `less`. The
environment variable REP_PAGER can be used to override the pager.
"#,
))
.flag(
Flag::new()
.short("-d")
.long("--delete-lines")
.help("Delete matching lines."),
)
.flag(
Flag::new()
.short("-s")
.long("--string-mode")
.help("Treat expressions as non-regex strings."),
)
.flag(
Flag::new()
.long("--no-color")
.help("Disable color."),
)
.flag(
Flag::new()
.long("--color")
.help("Enable color (the default if the output is a TTY)."),
)
.flag(
Flag::new()
.short("-V")
.long("--version")
.help("Prints version information."),
)
.flag(Flag::new().short("-f").long("--flags").help(
r#"Treat expressions as non-regex strings.
/** Regex flags. May be combined (like `-f mc`).
c - case-sensitive
i - case-insensitive
m - multi-line matching
w - match full words only
"#,
))
.arg(Arg::new("find"))
.arg(Arg::new("replace_with"))
.render();
let mut man_path =
std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
man_path.push("rep.1");
std::fs::write(man_path, page).expect("Error writing man page");
}