From c38cdd04532cf43bb741ca1cbe20288919cf21fe Mon Sep 17 00:00:00 2001 From: madomado Date: Tue, 19 Sep 2023 11:39:26 +0800 Subject: [PATCH] feat(andax/fns/io): add `sh_rc()`, `sh_stdout()`, `sh_stderr()` `sh_rc()` returns the return code of an output of `sh()`. This similarly applies to other fns. --- andax/src/fns/io.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/andax/src/fns/io.rs b/andax/src/fns/io.rs index 4a2a4f8..02082aa 100644 --- a/andax/src/fns/io.rs +++ b/andax/src/fns/io.rs @@ -46,6 +46,18 @@ type T = Result<(i32, String, String), Box>; /// We will let rhai handle all the nasty things. #[export_module] pub mod ar { + /// get the return code from the return value of `sh()` + pub fn sh_rc(o: (i32, String, String)) -> i32 { + o.0 + } + /// get stdout from the return value of `sh()` + pub fn sh_stdout(o: (i32, String, String)) -> String { + o.1 + } + /// get stderr from the return value of `sh()` + pub fn sh_stderr(o: (i32, String, String)) -> String { + o.2 + } /// run a command using `cmd` on Windows and `sh` on other systems #[instrument(skip(ctx))]