Skip to content

Commit c9a61dd

Browse files
authored
Allow async cli execution (#651)
1 parent f2494fa commit c9a61dd

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

crates/rune/src/cli.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,23 @@ impl<'a> Entry<'a> {
136136
}
137137
}
138138

139+
/// Run the configured application without starting a new tokio runtime.
140+
///
141+
/// This will take over stdout and stdin.
142+
pub async fn run_async(self) -> ! {
143+
match self.inner().await {
144+
Ok(exit_code) => {
145+
std::process::exit(exit_code as i32);
146+
}
147+
Err(error) => {
148+
let o = std::io::stderr();
149+
// ignore error because stdout / stderr might've been closed.
150+
let _ = format_errors(o.lock(), &error);
151+
std::process::exit(ExitCode::Failure as i32);
152+
}
153+
}
154+
}
155+
139156
async fn inner(mut self) -> Result<ExitCode> {
140157
let args = match Args::try_parse() {
141158
Ok(args) => args,

0 commit comments

Comments
 (0)