From 50f2aea280fed3d44df45ad9320b157e904c6f20 Mon Sep 17 00:00:00 2001 From: Fontrodona Nicolas <nicolas.fontrodona@ens-lyon.fr> Date: Fri, 13 Jan 2023 14:57:07 +0100 Subject: [PATCH] src/configt.rs: delete repositoy param and regex changes on it --- src/configt.rs | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/configt.rs b/src/configt.rs index c7ee9df..afeb4d1 100644 --- a/src/configt.rs +++ b/src/configt.rs @@ -4,7 +4,6 @@ use crate::prune::{new_prune, prune_launcher}; use clap::Args; use colored::Colorize; use home; -use regex::Regex; use std::{path::PathBuf, process::exit}; use toml; @@ -53,10 +52,7 @@ pub(crate) struct PartialPrune { /// current project pub fn get_borgconfig() -> Option<PathBuf> { let (mut config_path, _) = commit::check_path(); - config_path.push("config"); - if !config_path.is_file() { - return None; - } + config_path.push(".gblkconfig"); Some(config_path) } @@ -86,16 +82,16 @@ fn get_config(global: bool) -> PathBuf { match get_global_config() { Some(path) => path, None => { - eprintln!("local config not found !"); - exit(1); + println!("{} config not found !", "global".red()); + exit(0); } } } else { match get_borgconfig() { Some(path) => path, None => { - eprintln!("global config not found !"); - exit(1); + println!("{} config not found !", "local".yellow()); + exit(0); } } } @@ -122,14 +118,11 @@ pub fn parse_toml(global: bool) -> Config { }; if content.is_empty() { return Config { - repository: None, gblk_prune: None, gblk_remote: None, }; } - let re = Regex::new("id = (?P<first>[0-9a-z]+)\\W").unwrap(); - let nc = re.replace(&content, "id = '$first'"); - let config_str: Config = toml::from_str(&nc).unwrap(); + let config_str: Config = toml::from_str(&content).unwrap(); config_str } @@ -325,9 +318,7 @@ fn get_gblkconfig(full_config: &Config) -> GblkConfig { /// The string corresponding to toml file fn toml_to_string(config: &Config) -> String { let gblk_str = toml::to_string_pretty(&config).unwrap(); - let re = Regex::new("id = '(?P<first>[0-9a-z]+)'").unwrap(); - let nc = re.replace(&gblk_str, "id = $first").to_string(); - nc + gblk_str } /// Function used to write a configuration file -- GitLab