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
#[macro_use] extern crate serde_derive;
extern crate toml;
extern crate time;
extern crate core;
use std::fs::File;
use std::io::prelude::*;
use core::fmt;
use time::now;
pub mod types;
pub mod repo;
pub mod render;
impl fmt::Display for types::Date {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}-{}-{}", self.date.tm_mon, self.date.tm_mday, self.date.tm_year)
}
}
pub fn get_date() -> types::Date {
let mut t = now();
t.tm_year = t.tm_year + 1900;
types::Date { date: t }
}
pub fn read_toml_dir(template_path: &str) -> types::Project {
let mut template_file = File::open(template_path)
.expect("File could not be opened");
let mut template = String::new();
template_file.read_to_string(&mut template)
.expect("File read failed");
toml::from_str(&template).unwrap()
}
pub fn read_toml_config(config_path: std::path::PathBuf) -> types::Config {
let mut file = File::open(config_path)
.expect("File could not be opened.");
let mut toml_str = String::new();
file.read_to_string(&mut toml_str)
.expect("File read failed");
toml::from_str(&toml_str).unwrap()
}