commit 66b677bd2bdd923ef0b70083e00686f3ede7cca7
parent 0058b790ce465c8e3c3be7a5b7b03317db310024
Author: Asher Morgan <59518073+ashermorgan@users.noreply.github.com>
Date: Thu, 20 Jun 2024 16:07:25 -0700
Implement --copy flag
Diffstat:
2 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/src/cli.rs b/src/cli.rs
@@ -14,6 +14,10 @@ struct Args {
#[arg(short, long, num_args=0..)]
pub tag_rules: Vec<String>,
+ /// Copy files instead of creating links
+ #[arg(short, long)]
+ pub copy: bool,
+
/// Do a trial run without any permanent changes
#[arg(short = 'n', long)]
pub dry_run: bool,
@@ -23,5 +27,6 @@ struct Args {
pub fn run() {
let args = Args::parse();
let manifest_path = Path::new(&args.manifest);
- execute_manifest_file(&manifest_path, args.tag_rules, args.dry_run);
+ execute_manifest_file(&manifest_path, args.tag_rules, args.dry_run,
+ args.copy);
}
diff --git a/src/core.rs b/src/core.rs
@@ -5,16 +5,17 @@ use super::tags::tags_match;
use super::utils::{copy_file, link_file};
/// Execute the steps in a coliru manifest file according to a set of tag rules
-pub fn execute_manifest_file(path: &Path, tag_rules: Vec<String>, dry_run: bool)
-{
+pub fn execute_manifest_file(path: &Path, tag_rules: Vec<String>, dry_run: bool,
+ copy: bool) {
match parse_manifest_file(path) {
- Ok(manifest) => execute_manifest(manifest, tag_rules, dry_run),
+ Ok(manifest) => execute_manifest(manifest, tag_rules, dry_run, copy),
Err(why) => eprintln!("Error: {}", why),
};
}
/// Execute the steps in a coliru manifest according to a set of tag rules
-fn execute_manifest(manifest: Manifest, tag_rules: Vec<String>, dry_run: bool) {
+fn execute_manifest(manifest: Manifest, tag_rules: Vec<String>, dry_run: bool,
+ copy: bool) {
if let Err(why) = set_current_dir(manifest.base_dir) {
eprintln!("Error: {}", why);
return;
@@ -29,7 +30,11 @@ fn execute_manifest(manifest: Manifest, tag_rules: Vec<String>, dry_run: bool) {
println!("");
execute_copies(&step.copy, dry_run);
- execute_links(&step.link, dry_run);
+ if copy {
+ execute_copies(&step.link, dry_run);
+ } else {
+ execute_links(&step.link, dry_run);
+ }
}
}