passivized_test_support/
cli.rs1use core::future::Future;
2use std::fmt::Debug;
3use std::process::ExitCode;
4
5use log::{info, LevelFilter, warn};
6
7pub async fn run<E, F, Fut>(implementation: F) -> ExitCode
28where
29 E: Debug,
30 F: FnOnce() -> Fut,
31 Fut: Future<Output = Result<(), E>>
32{
33 super::logging::enable();
34
35 run_impl(implementation).await
36}
37
38pub async fn run_with_level<E, F, Fut>(implementation: F, log_level: LevelFilter) -> ExitCode
40where
41 E: Debug,
42 F: FnOnce() -> Fut,
43 Fut: Future<Output = Result<(), E>>
44{
45 super::logging::enable_with_level(log_level);
46
47 run_impl(implementation).await
48}
49
50pub async fn run_impl<E, F, Fut>(implementation: F) -> ExitCode
52where
53 E: Debug,
54 F: FnOnce() -> Fut,
55 Fut: Future<Output = Result<(), E>>
56{
57 info!("Hello, world.");
58
59 match implementation().await {
60 Err(e) => {
61 warn!("Failed: {:?}", e);
62 ExitCode::FAILURE
63 }
64 Ok(_) => {
65 info!("Done.");
66 ExitCode::SUCCESS
67 }
68 }
69}