-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.rs
More file actions
53 lines (42 loc) · 1.29 KB
/
Copy pathmain.rs
File metadata and controls
53 lines (42 loc) · 1.29 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
42
43
44
45
46
47
48
49
50
51
52
53
mod commands;
mod directory;
mod opts;
mod shape;
use std::fs::File;
use std::io::Read;
use anyhow::Result;
use opts::Opts;
#[cfg(test)]
pub mod tests;
pub const REPLACEABLE_NAME: &str = "{{__NAME__}}";
pub const REPLACEABLE_OUTPUT: &str = "{{__OUT__}}";
fn main() -> Result<(), anyhow::Error> {
let opts = Opts::opts()?;
let mut config_file = String::new();
File::open(&opts.config)?.read_to_string(&mut config_file)?;
let toml_config = toml::from_str(&config_file)?;
let dir_location = shape::get_lang_location(&toml_config, &opts.language)?;
let output_path = &opts.output.as_path().to_str().unwrap();
if let Some(commands) =
shape::get_commands(&toml_config, &opts.language, shape::CommandVariants::Before)?
{
for command in commands {
commands::exec(&command, &opts.project_name, &output_path)?;
}
}
directory::copy_dir_all(
&dir_location,
&opts.output,
&opts.project_name,
&output_path,
)?;
std::env::set_current_dir(&opts.output)?;
if let Some(commands) =
shape::get_commands(&toml_config, &opts.language, shape::CommandVariants::After)?
{
for command in commands {
commands::exec(&command, &opts.project_name, &output_path)?;
}
}
Ok(())
}