From 1b6b9273a51ea66a4667444e1ae80c4b6fe2c837 Mon Sep 17 00:00:00 2001 From: David <70471875+davidrotari19@users.noreply.github.com> Date: Tue, 12 Mar 2024 16:57:30 +0100 Subject: [PATCH] [runtimes] separate runtimes for diem_node and cli (#203) Co-authored-by: zoz <97761083+0xzoz@users.noreply.github.com> Co-authored-by: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com> Co-authored-by: Kalvis Kuskis <44435644+kalvkusk@users.noreply.github.com> Co-authored-by: Ubuntu --- tools/cli/src/main.rs | 69 +++++++++++++++++++++++++-------------- tools/cli/src/node_cli.rs | 2 +- 2 files changed, 45 insertions(+), 26 deletions(-) diff --git a/tools/cli/src/main.rs b/tools/cli/src/main.rs index af163c536..61016b6b7 100644 --- a/tools/cli/src/main.rs +++ b/tools/cli/src/main.rs @@ -29,36 +29,55 @@ enum Sub { Wallet(WalletCli), } -#[tokio::main] -async fn main() -> anyhow::Result<()> { +fn main() -> anyhow::Result<()> { let cli = LibraCli::parse(); match cli.command { - Some(Sub::Config(config_cli)) => { - config_cli.run().await?; - } - Some(Sub::Move(move_tool)) => { - move_tool - .execute() - .await - .map_err(|e| anyhow!("Failed to execute move tool, message: {}", &e))?; - } Some(Sub::Node(n)) => { - n.run().await?; - } - Some(Sub::Query(query_cli)) => { - query_cli.run().await?; - } - Some(Sub::Tower(tower_cli)) => { - tower_cli.run().await?; - } - Some(Sub::Txs(txs_cli)) => { - txs_cli.run().await?; - } - Some(Sub::Wallet(wallet_cli)) => { - wallet_cli.run().await?; + n.run()?; } _ => { - println!("\nliving is easy with eyes closed") + let rt = tokio::runtime::Runtime::new()?; + rt.block_on(async { + match cli.command { + Some(Sub::Config(config_cli)) => { + if let Err(e) = config_cli.run().await { + eprintln!("Failed to execute config tool, message: {}", &e); + } + } + Some(Sub::Move(move_tool)) => { + if let Err(e) = move_tool + .execute() + .await + .map_err(|e| anyhow!("Failed to execute move tool, message: {}", &e)) + { + eprintln!("Failed to execute move tool, message: {}", &e); + } + } + Some(Sub::Query(query_cli)) => { + if let Err(e) = query_cli.run().await { + eprintln!("Failed to execute query tool, message: {}", &e); + } + } + Some(Sub::Tower(tower_cli)) => { + if let Err(e) = tower_cli.run().await { + eprintln!("Failed to execute tower tool, message: {}", &e); + } + } + Some(Sub::Txs(txs_cli)) => { + if let Err(e) = txs_cli.run().await { + eprintln!("Failed to execute txs tool, message: {}", &e); + } + } + Some(Sub::Wallet(wallet_cli)) => { + if let Err(e) = wallet_cli.run().await { + eprintln!("Failed to execute wallet tool, message: {}", &e); + } + } + _ => { + println!("\nliving is easy with eyes closed") + } + } + }); } } diff --git a/tools/cli/src/node_cli.rs b/tools/cli/src/node_cli.rs index c518d49b4..f315e3bd3 100644 --- a/tools/cli/src/node_cli.rs +++ b/tools/cli/src/node_cli.rs @@ -13,7 +13,7 @@ pub struct NodeCli { } impl NodeCli { - pub async fn run(&self) -> anyhow::Result<()> { + pub fn run(&self) -> anyhow::Result<()> { // validators typically aren't looking for verbose logs. // but they can set it if they wish with RUST_LOG=info if std::env::var("RUST_LOG").is_err() {