-
Notifications
You must be signed in to change notification settings - Fork 11
/
build.rs
101 lines (94 loc) · 3.41 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
use std::env;
use std::fs::{File, create_dir};
use std::io::Write;
use std::path::PathBuf;
use man::prelude::*;
fn main() {
println!("cargo:rerun-if-changed=src");
built::write_built_file().expect("Failed to store build-time information");
generate_manpage();
}
fn get_assets_dir() -> PathBuf{
let out_dir = env::var("OUT_DIR").unwrap();
let out_path = PathBuf::from(&out_dir);
let mut path = out_path
.ancestors()
.nth(4)
.unwrap()
.to_owned();
path.push("assets");
if !path.exists() {
create_dir(&path).expect("could not create assets dir");
}
path
}
fn generate_manpage() {
let page = Manual::new("url-bot-rs")
.about("\
Standalone IRC bot; for resolving URLs posted, retrieving, and \
posting page titles to a configurable IRC servers and channels")
.author(Author::new("Ed Cragg").email("[email protected]"))
.flag(
Flag::new()
.long("--version")
.help("Print version information."),
)
.flag(
Flag::new()
.long("--help")
.help("Show usage."),
)
.flag(
Flag::new()
.short("-v")
.long("--verbose")
.help("\
Enable verbose mode. May be specified multiple times for \
more verbosity."),
)
.option(
Opt::new("configuration")
.short("-c")
.long("--conf")
.help("\
Path to read a single configuration file from. May be \
specified multiple times."),
)
.option(
Opt::new("configuration directory")
.short("-d")
.long("--conf-dir")
.help("\
Directory containing configurations. The path will be \
searched for valid configuration files, each \
configuration may contain connection information for a \
separate IRC network, with each configuration found \
starting a url-bot-rs instance on a thread. Any \
configuration files for which the network.enable field \
is false will be ignored. May be specified multiple \
times."),
)
.flag(
Flag::new()
.short("-t")
.long("--timestamp")
.help("\
Force timestamps to be printed, even when they would \
otherwise be disabled, e.g. when output is piped."),
)
.custom(
Section::new("configuration")
.paragraph("\
Most settings are read from the configuration file. This \
includes the details used to connect to an IRC server, \
features, and some runtime parameters. Running for the \
first time, a default-valued configuration will be \
generated in either the default XDG config path, or in the \
location specified with --conf.")
)
.render();
let assets_dir = get_assets_dir();
let dest_path = assets_dir.join("url-bot-rs.1");
let mut file = File::create(&dest_path).unwrap();
file.write_all(page.as_bytes()).unwrap();
}