main.rs
1 use std::env; 2 use std::path::PathBuf; 3 4 use clap::{Parser, Subcommand}; 5 use devimint::cli::CommonArgs; 6 use devimint::envs::FM_TEST_DIR_ENV; 7 use fedimint_core::fedimint_build_code_version_env; 8 use fedimint_core::util::{handle_version_hash_command, write_overwrite_async}; 9 use fedimint_logging::LOG_DEVIMINT; 10 use tokio::time::Instant; 11 use tracing::{debug, warn}; 12 13 #[derive(Parser)] 14 #[command(version)] 15 struct Args { 16 #[clap(subcommand)] 17 command: Cmd, 18 #[clap(flatten)] 19 common: CommonArgs, 20 } 21 22 #[derive(Subcommand)] 23 pub enum Cmd { 24 /// Run a base devimint command. 25 #[clap(flatten)] 26 Base(devimint::cli::Cmd), 27 /// Run a test. 28 #[clap(flatten)] 29 Test(devimint::tests::TestCmd), 30 } 31 32 async fn handle_command() -> anyhow::Result<()> { 33 let args = Args::parse(); 34 match args.command { 35 Cmd::Base(base) => devimint::cli::handle_command(base, args.common).await, 36 Cmd::Test(test) => devimint::tests::handle_command(test, args.common).await, 37 } 38 } 39 40 #[tokio::main] 41 async fn main() -> anyhow::Result<()> { 42 let start_time = Instant::now(); 43 handle_version_hash_command(fedimint_build_code_version_env!()); 44 let res = match handle_command().await { 45 Ok(r) => Ok(r), 46 Err(e) => { 47 if let Ok(test_dir) = env::var(FM_TEST_DIR_ENV) { 48 let ready_file = PathBuf::from(test_dir).join("ready"); 49 write_overwrite_async(ready_file, "ERROR").await?; 50 } else { 51 warn!(target: LOG_DEVIMINT, "{}", &format!("{FM_TEST_DIR_ENV} was not set")); 52 } 53 Err(e) 54 } 55 }; 56 debug!(target: LOG_DEVIMINT, elapsed_ms = %start_time.elapsed().as_millis(), "Finished"); 57 res 58 }