From f4b4400809bb40c23744210144a1f910f0c0e17a Mon Sep 17 00:00:00 2001
From: Fontrodona Nicolas <nicolas.fontrodona@ens-lyon.fr>
Date: Thu, 12 Jan 2023 11:27:09 +0100
Subject: [PATCH] src/main.rs src/prune.rs src/config_structure.rs
 src/configt.rs: move the configuration file structure in its own file
 config_structure.rs

---
 src/config_structure.rs | 78 ++++++++++++++++++++++++++++++++++++++
 src/configt.rs          | 83 +----------------------------------------
 src/main.rs             |  1 +
 src/prune.rs            |  3 +-
 4 files changed, 83 insertions(+), 82 deletions(-)
 create mode 100644 src/config_structure.rs

diff --git a/src/config_structure.rs b/src/config_structure.rs
new file mode 100644
index 0000000..7cca20e
--- /dev/null
+++ b/src/config_structure.rs
@@ -0,0 +1,78 @@
+/// This module contains the structure of the gblk config file
+use serde_derive::{Deserialize, Serialize};
+use toml::{self, Value};
+
+/// /// Structure containing the global definition of the borg config file
+#[derive(Debug, Deserialize, Serialize, Clone)]
+pub struct Config {
+    pub repository: Option<Repository>,
+    pub gblk_prune: Option<GblkConfig>,
+}
+
+/// Structure that store the current borg configuration for the project
+#[derive(Debug, Deserialize, Serialize, Clone)]
+pub struct Repository {
+    pub version: Value,
+    pub segments_per_dir: usize,
+    pub max_segment_size: usize,
+    pub append_only: usize,
+    pub storage_quota: usize,
+    pub additional_free_space: usize,
+    pub id: String,
+}
+
+/// Structure corresponding to the gblk prune config to automatically use
+/// inside a project
+#[derive(Debug, Deserialize, Serialize, Clone)]
+pub struct GblkConfig {
+    pub save_space: Option<bool>,
+    pub keep_within: Option<String>,
+    pub keep_last: Option<usize>,
+    pub keep_minutely: Option<usize>,
+    pub keep_hourly: Option<usize>,
+    pub keep_daily: Option<usize>,
+    pub keep_weekly: Option<usize>,
+    pub keep_monthly: Option<usize>,
+    pub keep_yearly: Option<usize>,
+    pub prefix: Option<String>,
+    pub glob_archives: Option<String>,
+}
+
+impl GblkConfig {
+    pub fn empty(&self) -> bool {
+        if self.save_space != None {
+            return false;
+        };
+        if self.keep_within != None {
+            return false;
+        };
+        if self.keep_last != None {
+            return false;
+        };
+        if self.keep_minutely != None {
+            return false;
+        };
+        if self.keep_hourly != None {
+            return false;
+        };
+        if self.keep_daily != None {
+            return false;
+        };
+        if self.keep_weekly != None {
+            return false;
+        };
+        if self.keep_monthly != None {
+            return false;
+        };
+        if self.keep_yearly != None {
+            return false;
+        };
+        if self.prefix != None {
+            return false;
+        };
+        if self.glob_archives != None {
+            return false;
+        };
+        true
+    }
+}
diff --git a/src/configt.rs b/src/configt.rs
index 5d9d75a..2420c60 100644
--- a/src/configt.rs
+++ b/src/configt.rs
@@ -1,12 +1,12 @@
 use crate::commit;
+use crate::config_structure::{Config, GblkConfig};
 use crate::prune::{new_prune, prune_launcher};
 use clap::Args;
 use colored::Colorize;
 use home;
 use regex::Regex;
-use serde_derive::{Deserialize, Serialize};
 use std::{path::PathBuf, process::exit};
-use toml::{self, Value};
+use toml;
 
 #[derive(Debug, Args)]
 pub(crate) struct PartialPrune {
@@ -47,85 +47,6 @@ pub(crate) struct PartialPrune {
     pub(crate) force: usize,
 }
 
-// ================================ toml structure of borg config
-
-/// Structure containing the global definition of the borg config file
-#[derive(Debug, Deserialize, Serialize, Clone)]
-pub struct Config {
-    repository: Option<Repository>,
-    gblk_prune: Option<GblkConfig>,
-}
-
-/// Structure that store the current borg configuration for the project
-#[derive(Debug, Deserialize, Serialize, Clone)]
-struct Repository {
-    version: Value,
-    segments_per_dir: usize,
-    max_segment_size: usize,
-    append_only: usize,
-    storage_quota: usize,
-    additional_free_space: usize,
-    id: String,
-}
-
-/// Structure corresponding to the gblk prune config to automatically use
-/// inside a project
-#[derive(Debug, Deserialize, Serialize, Clone)]
-pub struct GblkConfig {
-    pub save_space: Option<bool>,
-    pub keep_within: Option<String>,
-    pub keep_last: Option<usize>,
-    pub keep_minutely: Option<usize>,
-    pub keep_hourly: Option<usize>,
-    pub keep_daily: Option<usize>,
-    pub keep_weekly: Option<usize>,
-    pub keep_monthly: Option<usize>,
-    pub keep_yearly: Option<usize>,
-    pub prefix: Option<String>,
-    pub glob_archives: Option<String>,
-}
-
-impl GblkConfig {
-    fn empty(&self) -> bool {
-        if self.save_space != None {
-            return false;
-        };
-        if self.keep_within != None {
-            return false;
-        };
-        if self.keep_last != None {
-            return false;
-        };
-        if self.keep_minutely != None {
-            return false;
-        };
-        if self.keep_hourly != None {
-            return false;
-        };
-        if self.keep_daily != None {
-            return false;
-        };
-        if self.keep_weekly != None {
-            return false;
-        };
-        if self.keep_monthly != None {
-            return false;
-        };
-        if self.keep_yearly != None {
-            return false;
-        };
-        if self.prefix != None {
-            return false;
-        };
-        if self.glob_archives != None {
-            return false;
-        };
-        true
-    }
-}
-
-// =================== Functions
-
 /// Get the config file inside borg folder
 /// # Return
 /// A pathbuf variable containing the location of borg config file for the
diff --git a/src/main.rs b/src/main.rs
index 936a4e4..72b32b4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -15,6 +15,7 @@ mod init;
 mod list;
 mod mount;
 mod prune;
+mod config_structure;
 
 #[derive(Debug, Parser)]
 #[clap(name = "gblk")]
diff --git a/src/prune.rs b/src/prune.rs
index e3dc37e..1e01c2e 100644
--- a/src/prune.rs
+++ b/src/prune.rs
@@ -1,5 +1,6 @@
 use crate::commit;
-use crate::configt::{GblkConfig, PartialPrune};
+use crate::config_structure::GblkConfig;
+use crate::configt::PartialPrune;
 use clap::Args;
 use std::{
     collections::HashMap as HM,
-- 
GitLab