Fixed directory copy again, added on_install config
This commit is contained in:
parent
cee33671b2
commit
39f08615d8
@ -5,6 +5,7 @@ use serde::Deserialize;
|
||||
pub struct Module {
|
||||
#[serde(default)]
|
||||
pub ignore: Vec<String>,
|
||||
pub on_install: Option<String>,
|
||||
pub content: HashMap<String, String>
|
||||
}
|
||||
|
||||
|
@ -9,9 +9,9 @@ impl ToString for NamedModule {
|
||||
}
|
||||
}
|
||||
|
||||
fn install_mod(m: NamedModule) {
|
||||
fn install_mod(m: &NamedModule) {
|
||||
println!("Installing module {}...", m.0);
|
||||
'content_iter: for entry in m.1.content {
|
||||
'content_iter: for entry in &m.1.content {
|
||||
let src = std::path::Path::new("repo").join(&entry.0);
|
||||
if src.is_file() {
|
||||
if let Err(err) = std::fs::copy(src, entry.1) {
|
||||
@ -40,9 +40,9 @@ fn install_mod(m: NamedModule) {
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_mod(m: NamedModule) {
|
||||
fn collect_mod(m: &NamedModule) {
|
||||
println!("Collecting module {}...", m.0);
|
||||
'content_iter: for entry in m.1.content {
|
||||
'content_iter: for entry in &m.1.content {
|
||||
let dst = std::path::Path::new("repo").join(entry.0.as_str());
|
||||
let src = std::path::Path::new(entry.1.as_str());
|
||||
if src.is_file() {
|
||||
@ -78,7 +78,14 @@ pub fn install(config: &ModToml) {
|
||||
);
|
||||
|
||||
for m in to_install {
|
||||
install_mod(m);
|
||||
install_mod(&m);
|
||||
|
||||
if let Some(on_install) = &m.1.on_install {
|
||||
match std::process::Command::new("sh").arg("-c").arg(on_install).status() {
|
||||
Ok(status) => println!("Install command exited with {status}"),
|
||||
Err(err) => println!("Failed to execute on install command '{on_install}' with error:\n{err}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,7 +96,7 @@ pub fn collect(config: &ModToml) {
|
||||
);
|
||||
|
||||
for m in to_collect {
|
||||
collect_mod(m);
|
||||
collect_mod(&m);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,6 +59,7 @@ pub fn copy_dir(src_dir: &Path, dst_dir: &Path, ignored: &[String], pb: &indicat
|
||||
|
||||
let DirContent { dirs, files } = get_dir_content_filtered(src_dir, ignored, pb)?;
|
||||
|
||||
std::fs::create_dir_all(dst_dir).map_err(|e| e.to_string())?;
|
||||
for dir in dirs.into_iter().filter_map(trim_fn) {
|
||||
std::fs::create_dir_all(dst_dir.join(dir)).map_err(|e| e.to_string())?;
|
||||
pb.inc(1);
|
||||
|
Loading…
Reference in New Issue
Block a user