Kaynağa Gözat

taud: Abstract getting config file to a util function.

parazyd 4 yıl önce
ebeveyn
işleme
660c6184ca
2 değiştirilmiş dosya ile 7 ekleme ve 14 silme
  1. 5 12
      bin/taud/src/main.rs
  2. 2 2
      src/util/path.rs

+ 5 - 12
bin/taud/src/main.rs

@@ -14,7 +14,8 @@ use darkfi::{
     },
     },
     util::{
     util::{
         cli::{log_config, spawn_config, Config},
         cli::{log_config, spawn_config, Config},
-        expand_path, join_config_path,
+        expand_path,
+        path::get_config_path,
     },
     },
     Error, Result,
     Error, Result,
 };
 };
@@ -418,21 +419,13 @@ async fn main() -> Result<()> {
     let args = CliTaud::parse();
     let args = CliTaud::parse();
     let matches = CliTaud::command().get_matches();
     let matches = CliTaud::command().get_matches();
 
 
-    let config_path = if args.config.is_some() {
-        expand_path(&args.config.unwrap())?
-    } else {
-        join_config_path(&PathBuf::from("taud_config.toml"))?
-    };
-
-    // Spawn config file if it's not in place already.
-    spawn_config(&config_path, CONFIG_FILE_CONTENTS)?;
-
     let verbosity_level = matches.occurrences_of("verbose");
     let verbosity_level = matches.occurrences_of("verbose");
-
     let (lvl, conf) = log_config(verbosity_level)?;
     let (lvl, conf) = log_config(verbosity_level)?;
-
     TermLogger::init(lvl, conf, TerminalMode::Mixed, ColorChoice::Auto)?;
     TermLogger::init(lvl, conf, TerminalMode::Mixed, ColorChoice::Auto)?;
 
 
+    let config_path = get_config_path(args.config, "taud_config.toml")?;
+    spawn_config(&config_path, CONFIG_FILE_CONTENTS)?;
+
     let config: TauConfig = Config::<TauConfig>::load(config_path)?;
     let config: TauConfig = Config::<TauConfig>::load(config_path)?;
 
 
     let ex = Arc::new(Executor::new());
     let ex = Arc::new(Executor::new());

+ 2 - 2
src/util/path.rs

@@ -36,8 +36,8 @@ pub fn join_config_path(file: &Path) -> Result<PathBuf> {
 }
 }
 
 
 pub fn get_config_path(arg: Option<String>, fallback: &str) -> Result<PathBuf> {
 pub fn get_config_path(arg: Option<String>, fallback: &str) -> Result<PathBuf> {
-    if arg.is_some() {
-        expand_path(&arg.unwrap())
+    if let Some(a) = arg {
+        expand_path(&a)
     } else {
     } else {
         join_config_path(&PathBuf::from(fallback))
         join_config_path(&PathBuf::from(fallback))
     }
     }