refactored config

This commit is contained in:
Noah Swerhun 2024-03-05 10:37:16 -06:00
parent be088d3f14
commit d76e080841
2 changed files with 4 additions and 7 deletions

View file

@ -15,14 +15,12 @@ impl Config {
compile_commands: false,
}
}
pub fn new(table: &Table) -> Self {
let mut ret = Self::get_default();
pub fn set(&mut self, table: &Table) {
for k in table.keys() {
match &*k.to_owned() {
"build_dir" => {
if let Value::String(s) = table.get(k).unwrap() {
ret.build_dir = s.to_owned();
self.build_dir = s.to_owned();
} else {
panic!("fatal: {k} invalid type, must be a string.");
}
@ -30,7 +28,7 @@ impl Config {
"compile_commands" => {
if let Value::Boolean(b) = table.get(k).unwrap() {
eprintln!("warn: config.compile_commands has no functionality (yet)");
ret.compile_commands = *b;
self.compile_commands = *b;
} else {
panic!("fatal: {k} invalid type, must be a boolean.");
}
@ -38,6 +36,5 @@ impl Config {
_ => panic!("fatal: unrecognized key {k}."),
}
}
ret
}
}

View file

@ -91,7 +91,7 @@ fn main() {
for k in parsed_config.keys() {
if let Value::Table(t) = parsed_config.get(k).unwrap() {
if k == "config" {
config = Config::new(&t);
config.set(&t);
} else {
targets.push(Target::new(&t, k, Some(&targets[0])));
}