Browse Source

Update to use BTreeMaps, prettier config files"

Samuel W. Flint 3 years ago
parent
commit
b3f67a8137
5 changed files with 16 additions and 16 deletions
  1. 1 1
      Cargo.lock
  2. 1 1
      Cargo.toml
  3. 1 1
      flake.nix
  4. 10 10
      src/lib/config.rs
  5. 3 3
      src/lib/repository.rs

+ 1 - 1
Cargo.lock

@@ -171,7 +171,7 @@ dependencies = [
 
 [[package]]
 name = "sync-it"
-version = "1.0.2"
+version = "1.1.0"
 dependencies = [
  "clap",
  "home",

+ 1 - 1
Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "sync-it"
-version = "1.0.2"
+version = "1.1.0"
 authors = ["Samuel W. Flint <swflint@flintfam.org>"]
 edition = "2018"
 

+ 1 - 1
flake.nix

@@ -20,7 +20,7 @@
 
             src = ./.;
 
-            cargoSha256 = "Kk54lGkqD8TgUDsfKuu2d/EZMDJPIPueRexFHzeLGTg=";
+            cargoSha256 = "LVE4SvTxwYM0J/8FSzo5aeXeOD/FW9gomMQwVjYyulg=";
 
             meta = with pkgs.stdenv.lib; {
               description = "A simple, customizable synchronization tool.";

+ 10 - 10
src/lib/config.rs

@@ -1,5 +1,5 @@
 use serde::{Deserialize, Serialize};
-use std::collections::HashMap;
+use std::collections::BTreeMap;
 use std::path::PathBuf;
 use std::fs::{
     File,
@@ -29,13 +29,13 @@ use crate::lib::group::{
 #[derive(Serialize, Deserialize)]
 pub struct Config {
     #[serde(rename(serialize = "repo_type", deserialize = "repo_type"), default)]
-    pub repo_types: HashMap<String, RepoType>,
+    pub repo_types: BTreeMap<String, RepoType>,
     #[serde(rename(serialize = "repository", deserialize = "repository"), default)]
-    pub repositories: HashMap<String, Repository>,
+    pub repositories: BTreeMap<String, Repository>,
     #[serde(rename(serialize = "action", deserialize = "action"), default)]
-    pub actions: HashMap<String, Action>,
+    pub actions: BTreeMap<String, Action>,
     #[serde(rename(serialize = "group", deserialize = "group"), default)]
-    pub groups: HashMap<String, Group>,
+    pub groups: BTreeMap<String, Group>,
 }
 
 pub fn find_config_file(original: Option<&str>) -> PathBuf {
@@ -58,10 +58,10 @@ pub fn read_configuration_file(filename: &PathBuf) -> Config {
     match text {
         Err(_) => {
             let config = Config {
-                repo_types: HashMap::new(),
-                repositories: HashMap::new(),
-                actions: HashMap::new(),
-                groups: HashMap::new()
+                repo_types: BTreeMap::new(),
+                repositories: BTreeMap::new(),
+                actions: BTreeMap::new(),
+                groups: BTreeMap::new()
             };
             return config;
         },
@@ -70,7 +70,7 @@ pub fn read_configuration_file(filename: &PathBuf) -> Config {
 }
 
 pub fn write_configuration_file(filename: PathBuf, configuration: Config) -> std::io::Result<()> {
-    let toml = toml::to_string(&configuration).unwrap();
+    let toml = toml::to_string_pretty(&configuration).unwrap();
     let mut file = File::create(filename)?;
     file.write_all(toml.as_bytes())?;
     Ok(())

+ 3 - 3
src/lib/repository.rs

@@ -1,5 +1,5 @@
 use serde::{Deserialize, Serialize};
-use std::collections::HashMap;
+use std::collections::BTreeMap;
 use std::fmt;
 
 use crate::lib::config::Config;
@@ -17,11 +17,11 @@ pub struct Repository {
     #[serde(default)]
     pub disabled: bool,
     #[serde(default)]
-    pub options: HashMap<String, String>,
+    pub options: BTreeMap<String, String>,
 }
 
 pub fn register(config: &mut Config, name: &String, location: String, repo_type: String, options_strings: Vec<String>) {
-    let mut options_map: HashMap<String, String> = HashMap::new();
+    let mut options_map: BTreeMap<String, String> = BTreeMap::new();
     for option in options_strings {
         let option_pair: Vec<&str> = option.split("=").collect();
         options_map.insert(option_pair[0].to_string(), option_pair[1].to_string());