use std::path::Path;
use std::process::Command;
pub(crate) fn detect(dir: &Path) -> bool {
dir.join("uv.lock").exists()
}
pub(crate) fn install_cmd(frozen: bool) -> Command {
let mut c = super::program::command("uv");
c.arg("sync");
if frozen {
c.arg("--frozen");
}
c
}
pub(crate) fn run_cmd(script: &str, args: &[String]) -> Command {
let mut c = super::program::command("uv");
c.arg("run").arg(script).args(args);
c
}
pub(crate) fn exec_cmd(args: &[String]) -> Command {
let mut c = super::program::command("uvx");
c.args(args);
c
}
#[cfg(test)]
mod tests {
use super::{exec_cmd, run_cmd};
#[test]
fn run_uses_uv_run_with_script_and_args() {
let built: Vec<_> = run_cmd("greenpy", &[String::from("--flag")])
.get_args()
.map(|arg| arg.to_string_lossy().into_owned())
.collect();
assert_eq!(built, ["run", "greenpy", "--flag"]);
}
#[test]
fn exec_uses_uvx_passthrough() {
let args = [String::from("ruff"), String::from("check")];
let built: Vec<_> = exec_cmd(&args)
.get_args()
.map(|arg| arg.to_string_lossy().into_owned())
.collect();
assert_eq!(built, ["ruff", "check"]);
}
}