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
mod cli;
mod commands;
mod config_handler;
mod content_processor;
mod debug_print;
use relative_path::RelativePath;
use std::fs;
use config_handler::Config;
use debug_print::*;
fn main() {
let matches = cli::cli_builder().get_matches();
verbose_set(matches.is_present("verbose"));
let root_dir = matches.value_of("root");
match matches.subcommand() {
Some(("init", _)) => commands::init(root_dir.unwrap()),
Some(("build", _)) => {
let config = if let Ok(config) = fs::read_to_string(
RelativePath::new("./config.toml").to_logical_path(&root_dir.unwrap()),
) {
config
} else {
eprintln!("Failed reading config.toml");
return;
};
let config_toml: Config =
toml::from_str(config.as_str()).expect("invalid syntax in config.toml");
match config_toml.hl_theme.as_str() {
"base16-ocean.dark"
| "base16-eighties.dark"
| "base16-mocha.dark"
| "base16-ocean.light"
| "InspiredGitHub"
| "Solarized (dark)"
| "Solarized (light)" => (),
_ => {
eprintln!(
"Invalid syntax highlighting theme supplied - allowed values: {}",
r#"base16-ocean.dark" | "base16-eighties.dark" | "base16-mocha.dark" | "base16-ocean.light" | "InspiredGitHub" | "Solarized (dark)" | "Solarized (light)")"#
);
return;
}
}
Config::global_init(config_toml);
commands::build(
root_dir.unwrap(),
matches.subcommand_matches("build").unwrap().is_present("drafts"),
&RelativePath::new(
matches.subcommand_matches("build").unwrap().value_of("output").unwrap(),
)
.to_logical_path(root_dir.unwrap())
.to_string_lossy()
.to_string(),
)
}
_ => unreachable!(),
}
}