Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
20da7322f7 | |||
fdb052cfe1 | |||
8f7e61225d | |||
04cf74161c |
2 changed files with 25 additions and 15 deletions
|
@ -9,6 +9,7 @@ edition = "2021"
|
||||||
#copy_dir = "0.1.3"
|
#copy_dir = "0.1.3"
|
||||||
pico-args = "0.5.0"
|
pico-args = "0.5.0"
|
||||||
tera = "1.19.0"
|
tera = "1.19.0"
|
||||||
|
termion = "2.0.1"
|
||||||
toml = "0.7.6"
|
toml = "0.7.6"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
|
|
|
@ -7,12 +7,21 @@ use std::{
|
||||||
};
|
};
|
||||||
use core::error::Error;
|
use core::error::Error;
|
||||||
|
|
||||||
use toml::{ map::Map, Value };
|
|
||||||
use tera::{ Context, Tera };
|
use tera::{ Context, Tera };
|
||||||
|
use termion::{
|
||||||
|
color::{ self, Fg },
|
||||||
|
style
|
||||||
|
};
|
||||||
|
use toml::{ map::Map, Value };
|
||||||
|
|
||||||
|
static FAIL: Fg<color::LightRed> = Fg(color::LightRed);
|
||||||
|
static SUCCESS: Fg<color::LightGreen> = Fg(color::LightGreen);
|
||||||
|
static WARN: Fg<color::Yellow> = Fg(color::Yellow);
|
||||||
|
static RESET: Fg<color::Reset> = Fg(color::Reset);
|
||||||
|
|
||||||
pub fn apply(targets: &Vec<Map<String, Value>>) {
|
pub fn apply(targets: &Vec<Map<String, Value>>) {
|
||||||
let home = var("HOME").unwrap();
|
let home = var("HOME").unwrap();
|
||||||
println!("running apply:");
|
println!("{}running apply{}", style::Bold, style::Reset);
|
||||||
for target in targets {
|
for target in targets {
|
||||||
// get path and name
|
// get path and name
|
||||||
let path = target.get("path");
|
let path = target.get("path");
|
||||||
|
@ -22,12 +31,12 @@ pub fn apply(targets: &Vec<Map<String, Value>>) {
|
||||||
if path.is_none() {
|
if path.is_none() {
|
||||||
if i_name.is_some() {
|
if i_name.is_some() {
|
||||||
let name = i_name.unwrap().as_str().unwrap();
|
let name = i_name.unwrap().as_str().unwrap();
|
||||||
println!(" \"{name}\" is missing its path property; skipping");
|
println!(" {WARN}\"{name}\" is missing its path property; skipping{RESET}");
|
||||||
} else { println!(" skipping empty target"); }
|
} else { println!(" {WARN}skipping empty target{RESET}"); }
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if i_name.is_none() {
|
if i_name.is_none() {
|
||||||
println!(" target missing name; skipping");
|
println!(" {WARN}target missing name; skipping{RESET}");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,20 +51,20 @@ pub fn apply(targets: &Vec<Map<String, Value>>) {
|
||||||
|
|
||||||
// copy and print
|
// copy and print
|
||||||
let result = fs::copy(source, destination);
|
let result = fs::copy(source, destination);
|
||||||
if result.is_err() { println!(" failed to copy!"); }
|
if result.is_err() { println!(" {FAIL}failed to copy!{RESET}"); }
|
||||||
else { println!(" completed successfully"); }
|
else { println!(" {SUCCESS}completed successfully{RESET}"); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build(targets: &Vec<Map<String, Value>>, tera: &mut Tera, context: &Context) {
|
pub fn build(targets: &Vec<Map<String, Value>>, tera: &mut Tera, context: &Context) {
|
||||||
let home = var("HOME").unwrap();
|
let home = var("HOME").unwrap();
|
||||||
println!("running build:");
|
println!("{}running build{}", style::Bold, style::Reset);
|
||||||
for target in targets {
|
for target in targets {
|
||||||
// get name property
|
// get name property
|
||||||
let i_name = target.get("name");
|
let i_name = target.get("name");
|
||||||
// handle empty names gracefully
|
// handle empty names gracefully
|
||||||
if i_name.is_none() {
|
if i_name.is_none() {
|
||||||
println!(" target missing name; skipping");
|
println!(" {WARN}target missing name; skipping{RESET}");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +79,7 @@ pub fn build(targets: &Vec<Map<String, Value>>, tera: &mut Tera, context: &Conte
|
||||||
let error = render.err().unwrap();
|
let error = render.err().unwrap();
|
||||||
let message = error.source().unwrap();
|
let message = error.source().unwrap();
|
||||||
|
|
||||||
println!(" failed to render template:\n {message}");
|
println!(" {FAIL}failed to render template:\n {message}{RESET}");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,14 +89,14 @@ pub fn build(targets: &Vec<Map<String, Value>>, tera: &mut Tera, context: &Conte
|
||||||
let path = Path::new(&destination);
|
let path = Path::new(&destination);
|
||||||
let i_file = File::create(path);
|
let i_file = File::create(path);
|
||||||
if i_file.is_err() {
|
if i_file.is_err() {
|
||||||
println!(" failed to create destination file at {path:?}");
|
println!(" {FAIL}failed to create destination file at {path:?}{RESET}");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let mut file = i_file.unwrap();
|
let mut file = i_file.unwrap();
|
||||||
// write to destination file
|
// write to destination file
|
||||||
let written = write!(&mut file, "{output}");
|
let written = write!(&mut file, "{output}");
|
||||||
if written.is_err() { println!(" failed to write to destination file at {path:?}"); }
|
if written.is_err() { println!(" {FAIL}failed to write to destination file at {path:?}{RESET}"); }
|
||||||
else { println!(" completed successfully"); }
|
else { println!(" {SUCCESS}completed successfully{RESET}"); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue