Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -104,6 +104,10 @@ struct Opts {
#[arg(long, value_name = "ID")]
id: Option<String>,

/// 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,
}
Expand Down Expand Up @@ -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:?}"))?;

Expand Down Expand Up @@ -241,6 +257,7 @@ fn main() -> Result<()> {
meta.bin.display()
);
}
early_exit_if_no_run!();
exec(meta.bin, passthrough_args.clone());
}

Expand Down Expand Up @@ -269,6 +286,7 @@ fn main() -> Result<()> {
meta.bin.display()
);
}
early_exit_if_no_run!();
exec(meta.bin, passthrough_args.clone());
}
}
Expand Down Expand Up @@ -303,6 +321,8 @@ fn main() -> Result<()> {
},
)?;

early_exit_if_no_run!();

if verbose {
eprintln!("[scriptr] Executing: {}", bin_path.display());
}
Expand Down