forked from getzola/zola
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
73 lines (65 loc) · 2.12 KB
/
main.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
#[macro_use]
extern crate clap;
extern crate chrono;
extern crate term_painter;
extern crate staticfile;
extern crate iron;
extern crate mount;
extern crate notify;
extern crate url;
extern crate ws;
extern crate ctrlc;
extern crate site;
#[macro_use]
extern crate errors;
extern crate content;
extern crate front_matter;
extern crate utils;
extern crate rebuild;
use std::time::Instant;
mod cmd;
mod console;
mod cli;
mod prompt;
fn main() {
let matches = cli::build_cli().get_matches();
let config_file = matches.value_of("config").unwrap();
match matches.subcommand() {
("init", Some(matches)) => {
match cmd::create_new_project(matches.value_of("name").unwrap()) {
Ok(()) => (),
Err(e) => {
console::unravel_errors("Failed to create the project", &e);
::std::process::exit(1);
},
};
},
("build", Some(matches)) => {
console::info("Building site...");
let start = Instant::now();
let output_dir = matches.value_of("output_dir").unwrap();
match cmd::build(config_file, matches.value_of("base_url"), output_dir) {
Ok(()) => console::report_elapsed_time(start),
Err(e) => {
console::unravel_errors("Failed to build the site", &e);
::std::process::exit(1);
},
};
},
("serve", Some(matches)) => {
let interface = matches.value_of("interface").unwrap_or("127.0.0.1");
let port = matches.value_of("port").unwrap_or("1111");
let output_dir = matches.value_of("output_dir").unwrap();
let base_url = matches.value_of("base_url").unwrap();
console::info("Building site...");
match cmd::serve(interface, port, output_dir, base_url, config_file) {
Ok(()) => (),
Err(e) => {
console::unravel_errors("", &e);
::std::process::exit(1);
},
};
},
_ => unreachable!(),
}
}