Преглед изворни кода

bin/tau: add default value for rpc_listen

Dastan-glitch пре 4 година
родитељ
комит
713a937c6b
2 измењених фајлова са 11 додато и 2 уклоњено
  1. 4 1
      bin/tau/tau-cli/src/main.rs
  2. 7 1
      bin/tau/tau-cli/src/util.rs

+ 4 - 1
bin/tau/tau-cli/src/main.rs

@@ -168,7 +168,10 @@ async fn main() -> Result<()> {
 
     spawn_config(&config_path, CONFIG_FILE_CONTENTS)?;
 
-    let config: TauConfig = Config::<TauConfig>::load(config_path)?;
+    let config: TauConfig = match Config::<TauConfig>::load(config_path) {
+        Ok(c) => c,
+        Err(_) => TauConfig::default(),
+    };
 
     start(args, config).await
 }

+ 7 - 1
bin/tau/tau-cli/src/util.rs

@@ -2,7 +2,7 @@ use std::{
     env::{temp_dir, var},
     fs::{self, File},
     io::{self, Read, Write},
-    net::SocketAddr,
+    net::{IpAddr, Ipv4Addr, SocketAddr},
     ops::Index,
     process::Command,
 };
@@ -24,6 +24,12 @@ pub struct TauConfig {
     pub rpc_listen: SocketAddr,
 }
 
+impl Default for TauConfig {
+    fn default() -> Self {
+        Self { rpc_listen: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 11055) }
+    }
+}
+
 #[derive(Subcommand)]
 pub enum CliTauSubCommands {
     /// Add a new task