refactored config
This commit is contained in:
parent
be088d3f14
commit
d76e080841
2 changed files with 4 additions and 7 deletions
|
@ -15,14 +15,12 @@ impl Config {
|
||||||
compile_commands: false,
|
compile_commands: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn new(table: &Table) -> Self {
|
pub fn set(&mut self, table: &Table) {
|
||||||
let mut ret = Self::get_default();
|
|
||||||
|
|
||||||
for k in table.keys() {
|
for k in table.keys() {
|
||||||
match &*k.to_owned() {
|
match &*k.to_owned() {
|
||||||
"build_dir" => {
|
"build_dir" => {
|
||||||
if let Value::String(s) = table.get(k).unwrap() {
|
if let Value::String(s) = table.get(k).unwrap() {
|
||||||
ret.build_dir = s.to_owned();
|
self.build_dir = s.to_owned();
|
||||||
} else {
|
} else {
|
||||||
panic!("fatal: {k} invalid type, must be a string.");
|
panic!("fatal: {k} invalid type, must be a string.");
|
||||||
}
|
}
|
||||||
|
@ -30,7 +28,7 @@ impl Config {
|
||||||
"compile_commands" => {
|
"compile_commands" => {
|
||||||
if let Value::Boolean(b) = table.get(k).unwrap() {
|
if let Value::Boolean(b) = table.get(k).unwrap() {
|
||||||
eprintln!("warn: config.compile_commands has no functionality (yet)");
|
eprintln!("warn: config.compile_commands has no functionality (yet)");
|
||||||
ret.compile_commands = *b;
|
self.compile_commands = *b;
|
||||||
} else {
|
} else {
|
||||||
panic!("fatal: {k} invalid type, must be a boolean.");
|
panic!("fatal: {k} invalid type, must be a boolean.");
|
||||||
}
|
}
|
||||||
|
@ -38,6 +36,5 @@ impl Config {
|
||||||
_ => panic!("fatal: unrecognized key {k}."),
|
_ => panic!("fatal: unrecognized key {k}."),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ fn main() {
|
||||||
for k in parsed_config.keys() {
|
for k in parsed_config.keys() {
|
||||||
if let Value::Table(t) = parsed_config.get(k).unwrap() {
|
if let Value::Table(t) = parsed_config.get(k).unwrap() {
|
||||||
if k == "config" {
|
if k == "config" {
|
||||||
config = Config::new(&t);
|
config.set(&t);
|
||||||
} else {
|
} else {
|
||||||
targets.push(Target::new(&t, k, Some(&targets[0])));
|
targets.push(Target::new(&t, k, Some(&targets[0])));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue