Pārlūkot izejas kodu

Switch to using home::home_dir to get the config file (defaults)

Samuel W. Flint 3 gadi atpakaļ
vecāks
revīzija
698734ebfb
3 mainītis faili ar 19 papildinājumiem un 5 dzēšanām
  1. 10 0
      Cargo.lock
  2. 2 1
      Cargo.toml
  3. 7 4
      src/config.rs

+ 10 - 0
Cargo.lock

@@ -51,6 +51,15 @@ dependencies = [
  "libc",
 ]
 
+[[package]]
+name = "home"
+version = "0.5.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2456aef2e6b6a9784192ae780c0f15bc57df0e918585282325e8c8ac27737654"
+dependencies = [
+ "winapi",
+]
+
 [[package]]
 name = "libc"
 version = "0.2.77"
@@ -117,6 +126,7 @@ name = "sync-it"
 version = "0.1.0"
 dependencies = [
  "clap",
+ "home",
  "serde",
  "toml",
  "yaml-rust",

+ 2 - 1
Cargo.toml

@@ -10,4 +10,5 @@ edition = "2018"
 toml = "0.5.6"
 serde = {version = "1.0.116", features = ["derive"]}
 clap = {version = "2.33.3", features = ["yaml"]}
-yaml-rust = "0.3.5"
+yaml-rust = "0.3.5"
+home = "0.5.3"

+ 7 - 4
src/config.rs

@@ -7,6 +7,7 @@ use std::fs::{
 };
 use std::io::Write;
 
+use home::home_dir;
 #[derive(Serialize, Deserialize)]
 pub struct Config {
     #[serde(rename(serialize = "repo_type", deserialize = "repo_type"), default)]
@@ -72,11 +73,13 @@ pub struct Group {
 pub fn find_config_file(original: Option<&str>) -> PathBuf {
     match original {
         None => {
-            if PathBuf::from("~/.config/sync-it/config.toml").exists() {
-                return PathBuf::from("~/.config/sync-it/config.toml");
-            } else {
-                return PathBuf::from("~/.sync-it");
+            let config_name = PathBuf::from(".config/sync-it/config.toml");
+            let mut path_name = home_dir().unwrap().join(config_name);
+            if path_name.exists() {
+                return path_name;
             }
+            path_name = home_dir().unwrap().join(PathBuf::from(".sync-it.toml"));
+            return path_name;
         },
         Some(p) => return PathBuf::from(&p),
     }