Skip to content
Snippets Groups Projects
Verified Commit b5bcc552 authored by nfontrod's avatar nfontrod
Browse files

src/configt.rs: add gblk_project_name section in config

parent c3a0e78f
Branches
No related tags found
No related merge requests found
...@@ -77,12 +77,12 @@ pub fn get_global_config() -> Option<PathBuf> { ...@@ -77,12 +77,12 @@ pub fn get_global_config() -> Option<PathBuf> {
/// only the local one /// only the local one
/// # Return /// # Return
/// The path containing the local of global configuration /// The path containing the local of global configuration
fn get_config(global: bool) -> PathBuf { pub(crate) fn get_config(global: bool) -> PathBuf {
if global { if global {
match get_global_config() { match get_global_config() {
Some(path) => path, Some(path) => path,
None => { None => {
println!("{} config not found !", "global".red()); eprintln!("{} config not found !", "global".red());
exit(0); exit(0);
} }
} }
...@@ -90,7 +90,7 @@ fn get_config(global: bool) -> PathBuf { ...@@ -90,7 +90,7 @@ fn get_config(global: bool) -> PathBuf {
match get_borgconfig() { match get_borgconfig() {
Some(path) => path, Some(path) => path,
None => { None => {
println!("{} config not found !", "local".yellow()); eprintln!("{} config not found !", "local".red());
exit(0); exit(0);
} }
} }
...@@ -117,12 +117,18 @@ pub fn parse_toml(global: bool) -> Config { ...@@ -117,12 +117,18 @@ pub fn parse_toml(global: bool) -> Config {
Ok(s) => s, Ok(s) => s,
}; };
if content.is_empty() { if content.is_empty() {
return Config { if global {
gblk_prune: None, return Config::new(global);
gblk_remote: None, } else {
}; eprintln!(
"{}: Loccal config file should not be empty !",
"error".red()
);
exit(1);
}
} }
let config_str: Config = toml::from_str(&content).unwrap(); let config_str: Config = toml::from_str(&content).unwrap();
config_str.check_project_type(global, &config_file);
config_str config_str
} }
...@@ -346,6 +352,20 @@ pub fn write_config(config: &Config, global: bool) { ...@@ -346,6 +352,20 @@ pub fn write_config(config: &Config, global: bool) {
}; };
} }
/// Create a local config file
pub fn create_local_config() {
let conf = Config::new(false);
write_config(&conf, false);
}
/// Create a named local config file
/// # Arguments
/// - `name`: The name of the config file
pub fn create_named_local_config(name: &str) {
let conf = Config::new_named(name);
write_config(&conf, false);
}
/// Function that update the current gblk config file for the project folder /// Function that update the current gblk config file for the project folder
/// # Arguments /// # Arguments
/// - `key` : The key to update /// - `key` : The key to update
...@@ -404,6 +424,18 @@ pub fn remove_config(key: &str, global: bool) -> () { ...@@ -404,6 +424,18 @@ pub fn remove_config(key: &str, global: bool) -> () {
}; };
} }
/// Get the name of the current project
pub(crate) fn get_project_name() -> String {
let config = parse_toml(false);
match config.get_name() {
None => {
eprintln!("{}: Unable to get the project name !", "error".red());
exit(1);
}
Some(name) => name,
}
}
/// Function that recover the local or global gblk config /// Function that recover the local or global gblk config
/// # Description /// # Description
/// This function return the parsed local gblk config file if it exists. If /// This function return the parsed local gblk config file if it exists. If
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment