forked from argotorg/fe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew.rs
More file actions
41 lines (34 loc) · 1.06 KB
/
Copy pathnew.rs
File metadata and controls
41 lines (34 loc) · 1.06 KB
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
use clap::Args;
use include_dir::{include_dir, Dir};
use std::{fs, path::Path};
const TEMPLATE_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/src/template/src");
#[derive(Args)]
#[clap(about = "Create new fe project")]
pub struct NewProjectArgs {
name: String,
}
fn create_project(p: &Path) {
for file in TEMPLATE_DIR.entries() {
let f = file.as_file().unwrap();
fs::write(p.join(f.path()), f.contents()).unwrap();
}
}
pub fn create_new_project(args: NewProjectArgs) {
let project_path = Path::new(&args.name);
if project_path.exists() {
eprintln!(
"Error: destination directory {} already exists",
project_path.canonicalize().unwrap().display(),
);
std::process::exit(1)
}
let source_path = project_path.join("src");
match fs::create_dir_all(source_path.as_path()) {
Ok(_) => create_project(source_path.as_path()),
Err(err) => {
eprintln!("{}", err);
std::process::exit(1);
}
}
eprintln!("Created {}", project_path.display());
}