@@ -14,7 +14,6 @@ use std::{
1414 collections:: { HashMap , HashSet } ,
1515 fmt:: Display ,
1616 fs,
17- io:: IsTerminal ,
1817 path:: PathBuf ,
1918} ;
2019
@@ -71,28 +70,35 @@ pub struct ConfigFetcher {
7170 client : reqwest:: Client ,
7271 base_url : String ,
7372 config_vault : PathBuf ,
73+ non_interactive : bool ,
7474}
7575
7676impl Default for ConfigFetcher {
7777 /// Creates a new fetcher to interact with github.
7878 /// By default user's chain configuration vault is at: `~/.forc/chainspecs`
7979 fn default ( ) -> Self {
80+ Self :: new ( false )
81+ }
82+ }
83+
84+ impl ConfigFetcher {
85+ pub fn new ( non_interactive : bool ) -> Self {
8086 Self {
8187 client : reqwest:: Client :: new ( ) ,
8288 base_url : "https://api.github.com" . to_string ( ) ,
8389 config_vault : user_forc_directory ( ) . join ( CONFIG_FOLDER ) ,
90+ non_interactive,
8491 }
8592 }
86- }
8793
88- impl ConfigFetcher {
8994 #[ cfg( test) ]
9095 /// Override the base url, to be used in tests.
9196 pub fn with_base_url ( base_url : String ) -> Self {
9297 Self {
9398 client : reqwest:: Client :: new ( ) ,
9499 base_url,
95100 config_vault : user_forc_directory ( ) . join ( CONFIG_FOLDER ) ,
101+ non_interactive : false ,
96102 }
97103 }
98104
@@ -102,9 +108,14 @@ impl ConfigFetcher {
102108 client : reqwest:: Client :: new ( ) ,
103109 base_url,
104110 config_vault,
111+ non_interactive : false ,
105112 }
106113 }
107114
115+ fn non_interactive ( & self ) -> bool {
116+ self . non_interactive
117+ }
118+
108119 fn get_base_url ( & self ) -> & str {
109120 & self . base_url
110121 }
@@ -294,7 +305,7 @@ async fn validate_local_chainconfig(fetcher: &ConfigFetcher) -> anyhow::Result<(
294305 "Local node configuration files are missing at {}" ,
295306 local_conf_dir. display( )
296307 ) ) ;
297- let non_interactive = !std :: io :: stdout ( ) . is_terminal ( ) ;
308+ let non_interactive = fetcher . non_interactive ( ) ;
298309 if non_interactive {
299310 println_action_green (
300311 "Downloading" ,
@@ -335,7 +346,7 @@ async fn validate_remote_chainconfig(
335346 println_warning ( & format ! (
336347 "A network configuration update detected for {conf}, this might create problems while syncing with rest of the network"
337348 ) ) ;
338- let non_interactive = !std :: io :: stdout ( ) . is_terminal ( ) ;
349+ let non_interactive = fetcher . non_interactive ( ) ;
339350 if non_interactive {
340351 println_action_green (
341352 "Updating" ,
@@ -366,8 +377,11 @@ async fn validate_remote_chainconfig(
366377/// Check local state of the configuration file in the vault (if they exists)
367378/// and compare them to the remote one in github. If a change is detected asks
368379/// user if they want to update, and does the update for them.
369- pub async fn check_and_update_chain_config ( conf : ChainConfig ) -> anyhow:: Result < ( ) > {
370- let fetcher = ConfigFetcher :: default ( ) ;
380+ pub async fn check_and_update_chain_config (
381+ conf : ChainConfig ,
382+ non_interactive : bool ,
383+ ) -> anyhow:: Result < ( ) > {
384+ let fetcher = ConfigFetcher :: new ( non_interactive) ;
371385 match conf {
372386 ChainConfig :: Local => validate_local_chainconfig ( & fetcher) . await ?,
373387 remote_config => validate_remote_chainconfig ( & fetcher, & remote_config) . await ?,
0 commit comments