commit 1b044aed063273e742ee7b379b4431881e178aa2
parent 93f0823ddbb370d792ea3d55e4df824e47e1110e
Author: Asher Morgan <59518073+ashermorgan@users.noreply.github.com>
Date: Tue, 25 Jun 2024 11:14:13 -0700
Implement $COLIRU_RULES variable in run postfix
Diffstat:
4 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/README.md b/README.md
@@ -27,12 +27,15 @@ Each manifest contains a series of steps that are executed to install the
dotfiles.
Each step contains an array of tags and any number of copy, link, or run
commands.
+Each command is run from the directory containing the manifest file.
The copy command copies a file from a source (`src`) to a (`dst`).
The link command links a file from a source (`src`) to a (`dst`) using symbolic
links on Unix platforms and hard links on Windows.
Finally, the run command executes a script (`src`) from the command line, using
`sh` on Unix platforms and `powershell` on Windows, with an optional
`prefix` (e.g. `python3`) or `postfix` (e.g. `arg1 arg2 arg3`) string.
+Inside `postfix`, `$COLIRU_RULES` will be expanded into a space-delimited list
+ of the current tag rules.
Example YAML manifest:
diff --git a/examples/manifest.yml b/examples/manifest.yml
@@ -13,5 +13,5 @@ steps:
- run:
- src: baz
- postfix: arg1 arg2 arg3
+ postfix: arg1 $COLIRU_RULES arg2
tags: [ c ]
diff --git a/src/core.rs b/src/core.rs
@@ -33,7 +33,7 @@ fn execute_manifest(manifest: Manifest, tag_rules: Vec<String>, dry_run: bool,
} else {
execute_links(&step.link, dry_run, &step_str);
}
- execute_runs(&step.run, dry_run, &step_str);
+ execute_runs(&step.run, &tag_rules, dry_run, &step_str);
}
}
@@ -72,9 +72,12 @@ fn execute_links(links: &[CopyLinkOptions], dry_run: bool, step_str: &str) {
}
/// Execute the run commands specified in a coliru manifest step
-fn execute_runs(runs: &[RunOptions], dry_run: bool, step_str: &str) {
+fn execute_runs(runs: &[RunOptions], tag_rules: &[String], dry_run: bool,
+ step_str: &str) {
+
for run in runs {
- print!("{} Run {}", step_str, run.src);
+ let postfix = run.postfix.replace("$COLIRU_RULES", &tag_rules.join(" "));
+ print!("{} Run {} {} {}", step_str, run.prefix, run.src, postfix);
if dry_run {
println!(" (DRY RUN)");
@@ -82,7 +85,7 @@ fn execute_runs(runs: &[RunOptions], dry_run: bool, step_str: &str) {
}
println!("");
- if let Err(why) = run_script(&run.src, &run.prefix, &run.postfix) {
+ if let Err(why) = run_script(&run.src, &run.prefix, &postfix) {
eprintln!(" Error: {}", why);
}
}
diff --git a/src/manifest.rs b/src/manifest.rs
@@ -112,7 +112,7 @@ mod tests {
RunOptions {
src: String::from("baz"),
prefix: String::from(""),
- postfix: String::from("arg1 arg2 arg3"),
+ postfix: String::from("arg1 $COLIRU_RULES arg2"),
},
],
tags: vec![String::from("c")],