commit 6e0f79df001f5751ca0b755521803fcc303323cb
parent cc2628151c8d9850b3242994ee9d98425e499999
Author: Asher Morgan <59518073+ashermorgan@users.noreply.github.com>
Date: Sun, 23 Jun 2024 18:13:41 -0700
Implement run command postfix option
Diffstat:
5 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/examples/baz b/examples/baz
@@ -1,3 +1,3 @@
#!/usr/bin/sh
-echo 'baz!' > ~/baz
+echo "baz! (called with: $@)" > ~/baz
diff --git a/examples/manifest.yml b/examples/manifest.yml
@@ -13,4 +13,5 @@ steps:
- run:
- src: baz
+ postfix: arg1 arg2 arg3
tags: [ c ]
diff --git a/src/core.rs b/src/core.rs
@@ -82,7 +82,7 @@ fn execute_runs(runs: &[RunOptions], dry_run: bool) {
}
println!("");
- if let Err(why) = run_script(&run.src, &run.prefix) {
+ if let Err(why) = run_script(&run.src, &run.prefix, &run.postfix) {
eprintln!(" Error: {}", why);
}
}
diff --git a/src/manifest.rs b/src/manifest.rs
@@ -15,6 +15,9 @@ pub struct RunOptions {
#[serde(default)]
pub prefix: String,
+
+ #[serde(default)]
+ pub postfix: String,
}
#[derive(Debug, PartialEq, Deserialize)]
@@ -106,6 +109,7 @@ mod tests {
RunOptions {
src: String::from("baz"),
prefix: String::from(""),
+ postfix: String::from("arg1 arg2 arg3"),
},
],
tags: vec![String::from("c")],
diff --git a/src/utils.rs b/src/utils.rs
@@ -48,21 +48,22 @@ fn prepare_path(path: &str) -> Result<PathBuf> {
Ok(_dst)
}
-/// Execute a local shell script, optionally with a command prefix.
+/// Execute a local shell script, optionally with a command prefix or postfix.
///
/// Uses sh on Unix and PowerShell on Windows.
-pub fn run_script(path: &str, prefix: &str) -> Result<()> {
+pub fn run_script(path: &str, prefix: &str, postfix: &str) -> Result<()> {
+ // Use absolute() to avoid incompatible "UNC" paths on Windows:
+ // https://github.com/rust-lang/rust/issues/42869
+ let _path = absolute(path)?;
if cfg!(target_family = "unix") {
Command::new("sh")
.arg("-c")
- .arg(format!("{} {}", prefix, fs::canonicalize(path)?.display()))
+ .arg(format!("{} {} {}", prefix, _path.display(), postfix))
.status()?;
} else {
- // Use absolute() instead of canonicalize() to avoid incompatible paths:
- // https://github.com/rust-lang/rust/issues/42869
Command::new("powershell")
.args(["-ExecutionPolicy", "Bypass", "-Command"])
- .arg(format!("{} {}", prefix, absolute(path)?.display()))
+ .arg(format!("{} {} {}", prefix, _path.display(), postfix))
.status()?;
}
Ok(())