From 1054e211bef15917de634e3235c46b36000d6c81 Mon Sep 17 00:00:00 2001 From: Tomas Sandven Date: Thu, 7 May 2026 21:22:06 +0200 Subject: [PATCH] Add -n/--no-run option --- src/main.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index d5bb18f..b7266c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,7 @@ use std::{ io::{BufRead, BufReader, Read}, os::unix::process::CommandExt, path::{Path, PathBuf}, - process::{Command, Stdio}, + process::{Command, Stdio, exit}, time::UNIX_EPOCH, }; @@ -104,6 +104,10 @@ struct Opts { #[arg(long, value_name = "ID")] id: Option, + /// Do not run the script (useful for prebuilding or troubleshooting) + #[arg(short = 'n', long)] + no_run: bool, + /// Path to the Rust script (extension optional) script: PathBuf, } @@ -146,9 +150,21 @@ fn main() -> Result<()> { update, hash_only, id, + no_run, script, } = Opts::parse_from(scriptr_args); + macro_rules! early_exit_if_no_run { + () => { + if no_run { + if verbose { + eprintln!("[scriptr] Skipping execution (-n/--no-run)"); + } + exit(0); + } + }; + } + let script = fs::canonicalize(&script).with_context(|| format!("cannot resolve path {script:?}"))?; @@ -241,6 +257,7 @@ fn main() -> Result<()> { meta.bin.display() ); } + early_exit_if_no_run!(); exec(meta.bin, passthrough_args.clone()); } @@ -269,6 +286,7 @@ fn main() -> Result<()> { meta.bin.display() ); } + early_exit_if_no_run!(); exec(meta.bin, passthrough_args.clone()); } } @@ -303,6 +321,8 @@ fn main() -> Result<()> { }, )?; + early_exit_if_no_run!(); + if verbose { eprintln!("[scriptr] Executing: {}", bin_path.display()); }