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
extern crate clap;
use clap::{App, Arg, ArgMatches};
use std::fs;
use std::path::Path;
pub fn copy_dir(src: &Path, dest: &Path) -> std::io::Result<()> {
for entry in fs::read_dir(src).unwrap_or_else(|_| panic!("Cannot read dir for copy {:?}", src))
{
if let Ok(f) = entry {
let filetype = f.file_type()?;
if filetype.is_dir() {
let dir_name = dest.join(f.file_name());
fs::create_dir(&dir_name)?;
copy_dir(&f.path(), Path::new(&dir_name))?;
} else {
fs::copy(&f.path().as_os_str(), &dest.join(f.file_name()))
.unwrap_or_else(|_| panic!("Cannot copy {:?} to {:?}", &f, &dest));
}
}
}
Ok(())
}
pub fn get_args<'a>() -> ArgMatches<'a> {
App::new("blarf")
.version("1.0")
.author("Tom Ragle")
.about("Generates a static blog")
.arg(
Arg::with_name("articles")
.short("a")
.long("articles")
.help("Sets article source directory")
.required(true)
.takes_value(true),
)
.arg(
Arg::with_name("css")
.short("c")
.long("css")
.help("Sets css file")
.takes_value(true),
)
.arg(
Arg::with_name("email")
.short("e")
.long("email")
.help("Sets contact email address")
.takes_value(true),
)
.arg(
Arg::with_name("static")
.short("s")
.long("static")
.help("Sets static files source directory")
.takes_value(true),
)
.arg(
Arg::with_name("destination")
.short("d")
.long("dest")
.help("Sets destination directory")
.takes_value(true),
)
.get_matches()
}