From c9a61ddbdbe30aa44fb678faf84580acc7b166f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtte?= Date: Wed, 25 Oct 2023 21:02:01 +0200 Subject: [PATCH] Allow async cli execution (#651) --- crates/rune/src/cli.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/crates/rune/src/cli.rs b/crates/rune/src/cli.rs index 4c43147bf..ae06d5ba6 100644 --- a/crates/rune/src/cli.rs +++ b/crates/rune/src/cli.rs @@ -136,6 +136,23 @@ impl<'a> Entry<'a> { } } + /// Run the configured application without starting a new tokio runtime. + /// + /// This will take over stdout and stdin. + pub async fn run_async(self) -> ! { + match self.inner().await { + Ok(exit_code) => { + std::process::exit(exit_code as i32); + } + Err(error) => { + let o = std::io::stderr(); + // ignore error because stdout / stderr might've been closed. + let _ = format_errors(o.lock(), &error); + std::process::exit(ExitCode::Failure as i32); + } + } + } + async fn inner(mut self) -> Result { let args = match Args::try_parse() { Ok(args) => args,