config_structure.rs 2.64 KiB
use colored::Colorize;
/// 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>,
pub gblk_remote: Option<Vec<RemoteConfig>>,
}
/// 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
}
}
/// Structure that store the current borg configuration for the project
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct RemoteConfig {
pub name: String,
pub url: String,
}
impl RemoteConfig {
pub fn show(&self, tag: &str) -> () {
if tag == "" {
println!("{}: {}", self.name.green(), self.url.blue());
} else {
println!("{}: {}\t{}", self.name.green(), self.url.blue(), tag);
}
}
}