From 49dfd64b5b2dbd97e97353daf5b36311c8c5c079 Mon Sep 17 00:00:00 2001 From: Denis Kolodin Date: Sun, 13 Mar 2022 22:40:12 +0300 Subject: [PATCH] feat: add watch mode (like non-interactive with status) --- applications/tari_base_node/src/main.rs | 13 ++++++++++--- common/src/configuration/bootstrap.rs | 4 ++++ integration_tests/helpers/baseNodeProcess.js | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/applications/tari_base_node/src/main.rs b/applications/tari_base_node/src/main.rs index 9ccd486cd0..81334ede50 100644 --- a/applications/tari_base_node/src/main.rs +++ b/applications/tari_base_node/src/main.rs @@ -293,7 +293,7 @@ async fn run_node( target: LOG_TARGET, "Node has been successfully configured and initialized. Starting CLI loop." ); - task::spawn(cli_loop(context)); + task::spawn(cli_loop(context, bootstrap.watch_mode)); } if !config.force_sync_peers.is_empty() { warn!( @@ -387,7 +387,7 @@ async fn status_loop(mut context: CommandContext) { /// /// ## Returns /// Doesn't return anything -async fn cli_loop(mut context: CommandContext) { +async fn cli_loop(mut context: CommandContext, watch_mode: bool) { let parser = Parser::new(); commands::cli::print_banner(parser.get_commands(), 3); @@ -408,7 +408,11 @@ async fn cli_loop(mut context: CommandContext) { let mut software_update_notif = context.software_updater.new_update_notifier().clone(); let mut first_signal = false; let config = context.config.clone(); - let mut watch_task = Some(WatchCommand::default()); + let mut watch_task = if watch_mode { + Some(WatchCommand::default()) + } else { + None + }; loop { if let Some(command) = watch_task.take() { let line = command.line(); @@ -446,6 +450,9 @@ async fn cli_loop(mut context: CommandContext) { } } } + if watch_mode { + break; + } tokio::select! { res = reader.next_command() => { if let Some(event) = res { diff --git a/common/src/configuration/bootstrap.rs b/common/src/configuration/bootstrap.rs index f1e1b7e3e2..24a0138dcc 100644 --- a/common/src/configuration/bootstrap.rs +++ b/common/src/configuration/bootstrap.rs @@ -108,6 +108,9 @@ pub struct ConfigBootstrap { /// Run in non-interactive mode, with no UI. #[structopt(short, long, alias = "non-interactive")] pub non_interactive_mode: bool, + /// Run in watch mode (like non-interactive, but with running `watch` command) + #[structopt(long, alias = "watch")] + pub watch_mode: bool, /// This will rebuild the db, adding block for block in #[structopt(long, alias = "rebuild_db")] pub rebuild_db: bool, @@ -186,6 +189,7 @@ impl Default for ConfigBootstrap { init: false, create_id: false, non_interactive_mode: false, + watch_mode: false, rebuild_db: false, input_file: None, command: None, diff --git a/integration_tests/helpers/baseNodeProcess.js b/integration_tests/helpers/baseNodeProcess.js index f17c321299..036ec4df20 100644 --- a/integration_tests/helpers/baseNodeProcess.js +++ b/integration_tests/helpers/baseNodeProcess.js @@ -139,7 +139,7 @@ class BaseNodeProcess { }); fs.writeFileSync( `${this.baseDir}/start_node.sh`, - "export $(grep -v '^#' .env | xargs)\ncargo run --release --bin tari_base_node -- -b ." + "export $(grep -v '^#' .env | xargs)\ncargo run --release --bin tari_base_node -- --watch -b ." ); const ps = spawn(cmd, args, { cwd: this.baseDir,