commit aa93cd054adc044b2ba915633bc99fc097c83760
parent 5ed3ac2a02465ed68ab601609f24efe94ba6e1af
Author: Asher Morgan <59518073+ashermorgan@users.noreply.github.com>
Date: Thu, 20 Jun 2024 13:28:34 -0700
Implement --dry-run flag
Diffstat:
3 files changed, 24 insertions(+), 11 deletions(-)
diff --git a/src/cli.rs b/src/cli.rs
@@ -10,4 +10,8 @@ pub struct CLI {
/// The set of tag rules to enforce
#[arg(short, long, num_args=0..)]
pub tag_rules: Vec<String>,
+
+ /// Do a trial run without any permanent changes
+ #[arg(short = 'n', long)]
+ pub dry_run: bool,
}
diff --git a/src/core.rs b/src/core.rs
@@ -5,34 +5,43 @@ use super::tags::tags_match;
use super::utils::copy_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>) {
+pub fn execute_manifest_file(path: &Path, tag_rules: Vec<String>, dry_run: bool)
+{
match parse_manifest_file(path) {
- Ok(manifest) => execute_manifest(manifest, tag_rules),
+ Ok(manifest) => execute_manifest(manifest, tag_rules, dry_run),
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>) {
+fn execute_manifest(manifest: Manifest, tag_rules: Vec<String>, dry_run: bool) {
if let Err(why) = set_current_dir(manifest.base_dir) {
eprintln!("Error: {}", why);
return;
}
for (i, step) in manifest.steps.iter().enumerate() {
- if tags_match(&tag_rules, &step.tags) {
- println!("Step {}:", i+1);
- execute_copies(&step.copy);
- } else {
- println!("Step {}: skipped", i+1);
+ print!("Step {}:", i+1);
+ if !tags_match(&tag_rules, &step.tags) {
+ println!(" (skipped due to tag rules)");
+ continue;
}
+ println!("");
+
+ execute_copies(&step.copy, dry_run);
}
}
/// Execute the copy commands specified in a coliru manifest step
-fn execute_copies(copies: &[CopyOptions]) {
+fn execute_copies(copies: &[CopyOptions], dry_run: bool) {
for copy in copies {
- println!(" Copy {} to {}", copy.src, copy.dst);
+ print!(" Copy {} to {}", copy.src, copy.dst);
+ if dry_run {
+ println!(" (skipped due to --dry-run)");
+ return;
+ }
+ println!("");
+
if let Err(why) = copy_file(©.src, ©.dst) {
eprintln!(" Error: {}", why);
}
diff --git a/src/main.rs b/src/main.rs
@@ -9,5 +9,5 @@ use clap::Parser;
fn main() {
let args = cli::CLI::parse();
let manifest_path = std::path::Path::new(&args.manifest);
- core::execute_manifest_file(&manifest_path, args.tag_rules);
+ core::execute_manifest_file(&manifest_path, args.tag_rules, args.dry_run);
}