verify scripts
All checks were successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
JMARyA 2025-04-10 18:33:18 +02:00
parent b92c2625c2
commit aa231276af
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
3 changed files with 17 additions and 5 deletions

View file

@ -8,6 +8,7 @@ pub fn get_args() -> clap::ArgMatches {
.about("Bootstrap a new repository from base repository")
.arg(arg!(<BASE> "Base repository").required(true))
.arg(arg!(<NEW> "Repository name").required(true))
.arg(arg!(--verify "Verify scripts before running them"))
.alias("bs"),
)
.subcommand(

View file

@ -152,8 +152,18 @@ pub fn build_script_vars(expose: Option<Vec<String>>, vars: &[AskValue]) -> Stri
String::new()
}
pub fn do_script(action: &ScriptAction, vars: &[AskValue], name: &str) {
pub fn do_script(action: &ScriptAction, vars: &[AskValue], name: &str, verify: bool) {
let pre = build_script_vars(action.expose.clone(), &vars);
if verify {
let script =
std::fs::read_to_string(std::path::Path::new(name).join(&action.script)).unwrap();
println!("Running script:\n{pre}\n{script}");
if !inquire::prompt_confirmation("Run this script?").unwrap() {
return;
}
}
println!("Running script '{}'", action.script);
Exec::cmd("sh")
.arg("-c")
@ -187,7 +197,7 @@ pub fn do_replace(action: &ReplaceAction, name: &str, vars: &[AskValue]) {
}
/// Bootstrap a git repository using a base template
pub fn bootstrap(base: &str, name: &str) {
pub fn bootstrap(base: &str, name: &str, verify: bool) {
Exec::cmd("git")
.arg("clone")
.arg(base)
@ -281,10 +291,10 @@ pub fn bootstrap(base: &str, name: &str) {
};
if eval(&when, &vars) {
do_script(&action, &vars, name);
do_script(&action, &vars, name, verify);
}
} else {
do_script(&action, &vars, name);
do_script(&action, &vars, name, verify);
}
}
}

View file

@ -14,7 +14,8 @@ fn main() {
Some(("bootstrap", bs_args)) => {
let base = bs_args.get_one::<String>("BASE").unwrap();
let repo = bs_args.get_one::<String>("NEW").unwrap();
bootstrap(base, repo);
let verify = bs_args.get_flag("verify");
bootstrap(base, repo, verify);
}
Some(("new", new_args)) => {
let branch: &String = new_args.get_one("BRANCH").unwrap();