fix(config): add option to last category
This commit is contained in:
parent
eaacff0e55
commit
a5c5f4a713
@ -13,6 +13,7 @@ pub fn config_set(args: ConfigSetArgs) {
|
||||
// configure possible options and their associated category
|
||||
let mut option_categories: HashMap<&str, &str> = HashMap::new();
|
||||
option_categories.insert("force_insecure", "core");
|
||||
option_categories.insert("token", "core");
|
||||
|
||||
let name = args.name.unwrap().next().unwrap();
|
||||
let value = args.value.unwrap().next().unwrap();
|
||||
@ -28,7 +29,7 @@ pub fn config_set(args: ConfigSetArgs) {
|
||||
}
|
||||
|
||||
|
||||
fn find_option_in_cat(category: &str, option: &str) -> Option<String> {
|
||||
pub fn find_option_in_cat(category: &str, option: &str) -> Option<String> {
|
||||
let mut root = path::nextsync();
|
||||
root.push("config");
|
||||
|
||||
@ -83,8 +84,14 @@ pub fn write_option_in_cat(category: &str, option: &str, value: &str) -> io::Res
|
||||
let trimmed_line = line.trim();
|
||||
|
||||
if trimmed_line.starts_with('[') && trimmed_line.ends_with(']') {
|
||||
// if we were already in target category we are now leaving it
|
||||
// add option only if not found before
|
||||
if in_target_category && !option_found {
|
||||
writeln!(&mut tmp_file, "\t{} = {}", option, value)?;
|
||||
} else if !in_target_category {
|
||||
in_target_category = trimmed_line == format!("[{}]", category);
|
||||
}
|
||||
}
|
||||
|
||||
if in_target_category && !option_found && trimmed_line.starts_with(&format!("{} =", option)) {
|
||||
// Option already exists, update its value
|
||||
@ -96,8 +103,13 @@ pub fn write_option_in_cat(category: &str, option: &str, value: &str) -> io::Res
|
||||
}
|
||||
}
|
||||
|
||||
if !option_found {
|
||||
// If the option doesn't exist, add it to the category
|
||||
// add to last category
|
||||
if in_target_category && !option_found {
|
||||
writeln!(&mut tmp_file, "\t{} = {}", option, value)?;
|
||||
}
|
||||
|
||||
// if the category didn't exist create it and add the option
|
||||
if !in_target_category {
|
||||
writeln!(&mut tmp_file, "[{}]", category)?;
|
||||
writeln!(&mut tmp_file, "\t{} = {}", option, value)?;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user