From 6741bb129bdb70b6a7731fd3ff68a9b41fa1a5cf Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 2 Jul 2025 21:34:43 +0100 Subject: [PATCH] WIP start of a script runner tool --- script-runner/Cargo.lock | 15 +++++++++++++++ script-runner/Cargo.toml | 14 ++++++++++++++ script-runner/examples/echo.rs | 3 +++ script-runner/main.rs | 23 +++++++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 script-runner/Cargo.lock create mode 100644 script-runner/Cargo.toml create mode 100644 script-runner/examples/echo.rs create mode 100644 script-runner/main.rs diff --git a/script-runner/Cargo.lock b/script-runner/Cargo.lock new file mode 100644 index 0000000..7ab7789 --- /dev/null +++ b/script-runner/Cargo.lock @@ -0,0 +1,15 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "script-runner" +version = "0.1.0" +dependencies = [ + "simple-toml-parser", +] + +[[package]] +name = "simple-toml-parser" +version = "0.0.0" +source = "git+https://github.com/kaleidawave/simple-toml-parser.git?branch=improvements#6b470cc4c474a55b44e3f946211ad63132b30510" diff --git a/script-runner/Cargo.toml b/script-runner/Cargo.toml new file mode 100644 index 0000000..b924d8d --- /dev/null +++ b/script-runner/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "script-runner" +version = "0.1.0" +edition = "2024" + +[dependencies] +simple-toml-parser = { git = "https://github.com/kaleidawave/simple-toml-parser.git", branch = "improvements" } + +[[bin]] +name = "script-runner" +path = "./main.rs" + +[package.metadata.commands] +echo = "./target/debug/examples/echo.exe hello world" diff --git a/script-runner/examples/echo.rs b/script-runner/examples/echo.rs new file mode 100644 index 0000000..cf89255 --- /dev/null +++ b/script-runner/examples/echo.rs @@ -0,0 +1,3 @@ +fn main() { + println!("{args:?}", args=std::env::args().skip(1).collect::>()); +} \ No newline at end of file diff --git a/script-runner/main.rs b/script-runner/main.rs new file mode 100644 index 0000000..b9e96f6 --- /dev/null +++ b/script-runner/main.rs @@ -0,0 +1,23 @@ +use simple_toml_parser::{matches, parse as parse_toml, RootTOMLValue}; +use std::process::{Command, Stdio}; + +fn main() { + let cargo_toml = std::fs::read_to_string("./Cargo.toml").unwrap(); + let arg = std::env::args().nth(1).unwrap_or_default(); + + parse_toml(&cargo_toml, |keys, value| { + let matched = matches(&["package", "metadata", "commands", &arg], keys); + if matched { + if let RootTOMLValue::String(run) = value { + let mut args = run.split(' '); + let name = args.next().expect("no command name"); + let mut command = Command::new(name); + command.args(args.collect::>()); + command.stdout(Stdio::inherit()); + command.stderr(Stdio::inherit()); + let _ = command.spawn(); + } + } + }) + .unwrap(); +}