Skip to content

Commit

Permalink
feat: add watch mode (like non-interactive with status)
Browse files Browse the repository at this point in the history
  • Loading branch information
therustmonk committed Mar 13, 2022
1 parent 6254f0e commit 49dfd64
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
13 changes: 10 additions & 3 deletions applications/tari_base_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down Expand Up @@ -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);

Expand All @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions common/src/configuration/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/helpers/baseNodeProcess.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 49dfd64

Please sign in to comment.