Skip to content

Commit df3ae87

Browse files
committed
non-interactive for tests
1 parent 8a52f69 commit df3ae87

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

forc-plugins/forc-node/src/chain_config.rs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::{
1414
collections::{HashMap, HashSet},
1515
fmt::Display,
1616
fs,
17+
io::IsTerminal,
1718
path::PathBuf,
1819
};
1920

@@ -293,9 +294,19 @@ async fn validate_local_chainconfig(fetcher: &ConfigFetcher) -> anyhow::Result<(
293294
"Local node configuration files are missing at {}",
294295
local_conf_dir.display()
295296
));
296-
// Ask user if they want to update the chain config.
297-
let update = ask_user_yes_no_question("Would you like to download network configuration?")?;
298-
if update {
297+
let non_interactive = !std::io::stdout().is_terminal();
298+
if non_interactive {
299+
println_action_green(
300+
"Downloading",
301+
"local network configuration (non-interactive mode).",
302+
);
303+
}
304+
let should_download = if non_interactive {
305+
true
306+
} else {
307+
ask_user_yes_no_question("Would you like to download network configuration?")?
308+
};
309+
if should_download {
299310
fetcher.download_config(&ChainConfig::Local).await?;
300311
} else {
301312
bail!(
@@ -324,10 +335,22 @@ async fn validate_remote_chainconfig(
324335
println_warning(&format!(
325336
"A network configuration update detected for {conf}, this might create problems while syncing with rest of the network"
326337
));
327-
// Ask user if they want to update the chain config.
328-
let update = ask_user_yes_no_question("Would you like to update network configuration?")?;
329-
if update {
330-
println_action_green("Updating", &format!("configuration files for {conf}",));
338+
let non_interactive = !std::io::stdout().is_terminal();
339+
if non_interactive {
340+
println_action_green(
341+
"Updating",
342+
&format!("configuration files for {conf} (non-interactive mode)",),
343+
);
344+
}
345+
let should_update = if non_interactive {
346+
true
347+
} else {
348+
ask_user_yes_no_question("Would you like to update network configuration?")?
349+
};
350+
if should_update {
351+
if !non_interactive {
352+
println_action_green("Updating", &format!("configuration files for {conf}",));
353+
}
331354
fetcher.download_config(conf).await?;
332355
println_action_green(
333356
"Finished",

0 commit comments

Comments
 (0)