Skip to content

Commit

Permalink
Allow async cli execution (#651)
Browse files Browse the repository at this point in the history
  • Loading branch information
Roba1993 authored Oct 25, 2023
1 parent f2494fa commit c9a61dd
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions crates/rune/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExitCode> {
let args = match Args::try_parse() {
Ok(args) => args,
Expand Down

0 comments on commit c9a61dd

Please sign in to comment.