fix: resolve CLI connections before async runtime
This commit is contained in:
+27
-3
@@ -74,9 +74,12 @@ impl fmt::Display for ParseError {
|
|||||||
|
|
||||||
impl std::error::Error for ParseError {}
|
impl std::error::Error for ParseError {}
|
||||||
|
|
||||||
#[tokio::main]
|
fn main() -> ExitCode {
|
||||||
async fn main() -> ExitCode {
|
start_cli(parse_args)
|
||||||
let mode = match parse_args() {
|
}
|
||||||
|
|
||||||
|
fn start_cli(parse: impl FnOnce() -> Result<Mode, ParseError>) -> ExitCode {
|
||||||
|
let mode = match parse() {
|
||||||
Ok(mode) => mode,
|
Ok(mode) => mode,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("yoi: {e}");
|
eprintln!("yoi: {e}");
|
||||||
@@ -85,6 +88,11 @@ async fn main() -> ExitCode {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
run(mode)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn run(mode: Mode) -> ExitCode {
|
||||||
match mode {
|
match mode {
|
||||||
Mode::Help => {
|
Mode::Help => {
|
||||||
print_help();
|
print_help();
|
||||||
@@ -1825,6 +1833,22 @@ fn print_memory_lint_help() {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn cli_parses_connection_before_starting_tokio_runtime() {
|
||||||
|
let mut parsed = false;
|
||||||
|
|
||||||
|
let _ = start_cli(|| {
|
||||||
|
assert!(
|
||||||
|
tokio::runtime::Handle::try_current().is_err(),
|
||||||
|
"connection resolution must run before the CLI Tokio runtime starts"
|
||||||
|
);
|
||||||
|
parsed = true;
|
||||||
|
Ok(Mode::Help)
|
||||||
|
});
|
||||||
|
|
||||||
|
assert!(parsed);
|
||||||
|
}
|
||||||
use crate::cli_connection::CliConnectionInput;
|
use crate::cli_connection::CliConnectionInput;
|
||||||
use client::{BackendTarget, StandaloneTarget, Target, TargetKind, WorkerListRequest};
|
use client::{BackendTarget, StandaloneTarget, Target, TargetKind, WorkerListRequest};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|||||||
Reference in New Issue
Block a user