diff --git a/.DS_Store b/.DS_Store index 4822d6f..e235028 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 835e4fd..f179f3e 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -17,6 +17,8 @@ jobs: archive: tar.gz - target: x86_64-apple-darwin archive: zip + - target: armv7-unknown-linux-gnueabihf + archive: zip steps: - uses: actions/checkout@master diff --git a/.gitignore b/.gitignore index 8eb991e..a629241 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .DS_Store /target .idea -tmp \ No newline at end of file +tmp +*.sh \ No newline at end of file diff --git a/clone.sh b/clone.sh deleted file mode 100644 index 42f89aa..0000000 --- a/clone.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/zsh -cargo run -- \ - -r https://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:x-oauth-basic@github.com/trpouh/test-playbook.git \ - -b main \ - --tmp-dir tmp \ - -t examples \ - -s sermon.yaml \ No newline at end of file diff --git a/kickstarter/install-mac.sh b/kickstarter/install-mac.sh index 43bb2ce..31b769c 100644 --- a/kickstarter/install-mac.sh +++ b/kickstarter/install-mac.sh @@ -23,5 +23,5 @@ psalms: - type: Hello EOT -echo "[preacher] start your first sermon with './preacher --tmp-dir ../tmp'" +echo "[preacher] start your first sermon with './preacher'" diff --git a/local.sh b/local.sh deleted file mode 100644 index 8916c8d..0000000 --- a/local.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/zsh -cargo run -- \ - --source-folder examples \ - --tmp-dir tmp \ - -s hello-sermon.yaml \ No newline at end of file diff --git a/src/lib/io.rs b/src/lib/io.rs index feece08..e1c25e0 100644 --- a/src/lib/io.rs +++ b/src/lib/io.rs @@ -28,13 +28,33 @@ pub fn clone_to_dir(repo: &str, target_dir: &str, branch: Option<&str>) { } } -pub fn copy_all_files_to_dir(source_dir: &str, target_dir: &str) { - copy_dir(&format!("{}/.", source_dir), &format!("{}/", target_dir)); +pub struct CopyOptions<'a> { + pub source_dir: &'a str, + pub target_dir: &'a str, + pub exclude: Option>, + pub without_parent_folder: Option, + pub ensure_target_exists: Option } -pub fn copy_dir(source_dir: &str, target_dir: &str) { - let mut command = Command::new("cp"); - command.arg("-r").arg(source_dir).arg(target_dir); +pub fn copy_dir(copy_options: &CopyOptions) { + + if copy_options.ensure_target_exists.unwrap_or(false) { + create_dir(copy_options.target_dir, true); + } + + let mut command = Command::new("rsync"); + + let source_dir = if copy_options.without_parent_folder.unwrap_or_else(|| false) { + format!("{}/.", copy_options.source_dir) + } else { + copy_options.source_dir.to_owned() + }; + + copy_options.exclude.as_ref().unwrap_or(&Vec::default()).iter().for_each(|dir| { + command.args(["--exclude", dir]); + }); + + command.arg("-r").arg(&source_dir).arg(copy_options.target_dir); if let Ok(mut child) = command.spawn() { let exit_status = child.wait(); @@ -43,7 +63,7 @@ pub fn copy_dir(source_dir: &str, target_dir: &str) { if status.success() { println!( "Successfully copied source dir {} to dir: {} (Status: {})", - source_dir, target_dir, status + source_dir, copy_options.target_dir, status ); } else { println!("Copying not successful"); diff --git a/src/sermon.rs b/src/sermon.rs index 0f12411..f55bebb 100644 --- a/src/sermon.rs +++ b/src/sermon.rs @@ -4,7 +4,7 @@ use std::fmt::Debug; use std::fs; use std::path::Path; -use crate::lib::io; +use crate::lib::io::{self, CopyOptions}; use crate::psalms::hello::HelloPsalm; use crate::worship::Worship; @@ -45,7 +45,7 @@ impl Sermon { pub fn initialize(worship: &Worship) -> Result { - let tmp_dir = &worship.tmp_dir; + let tmp_dir = worship.tmp_dir.as_str(); if let Some(repo) = &worship.repo { println!("Cloning git repo {} into folder {}", repo, tmp_dir); @@ -62,8 +62,17 @@ pub fn initialize(worship: &Worship) -> Result { //TODO: same directory creates recursion if let Ok(_) = fs::read_to_string(sermon_path) { println!("Copying local folder {} into folder {}", worship.source_folder, tmp_dir); - io::create_dir(&tmp_dir, true); - io::copy_all_files_to_dir(&worship.source_folder, tmp_dir); + + let copy_opts: CopyOptions = CopyOptions { + source_dir: &worship.source_folder, + target_dir: tmp_dir, + ensure_target_exists: Some(true), + exclude: Some([tmp_dir].to_vec()), + without_parent_folder: Some(true) + }; + + io::copy_dir(©_opts);//&worship.source_folder, tmp_dir); + } else { println!("Couldn't find sermon {} in local folder: {}", &worship.sermon, &worship.source_folder); return Err("No sermon found".to_string()); diff --git a/src/worship.rs b/src/worship.rs index 85a0937..9a42ae3 100644 --- a/src/worship.rs +++ b/src/worship.rs @@ -19,7 +19,7 @@ pub struct Worship { #[arg(short, long, default_value_t = String::from("./"))] pub target_folder: String, - #[arg(long, default_value_t = String::from("~/.preacher/tmp"))] + #[arg(long, default_value_t = String::from(".preacher/tmp"))] pub tmp_dir: String, }