trynd / wren

Linux boot platform that provides a portable, multi-system, run-in-memory Linux environment.
GNU General Public License v3.0
0 stars 1 forks source link

loadRunEnvConf() defaults #14

Open codewithmichael opened 9 years ago

codewithmichael commented 9 years ago

Addresses issue #13

Here's the most straight-forward and thorough way that first came to mind for setting default values in case of missing or corrupt conf files. I didn't thoroughly test it because it's way too much code to add for such a simple functional advantage.

I'm going to look into a simpler for i in array eval loop, but it's worth posting the pull request to show what I think we should be going for.

Basically, there are 3 possible states in which we would want variable defaults:

Because an error prone conf file probably shouldn't be trusted, I think the first and third cases ought to (re)define the entire set of expected variables. But the second case is tricky when a variable is intentionally blank (set to empty) or some variables depend on the values of others. There isn't a lot we can do if a variable has been set within a conf file that references another undefined variable, but we should ensure they are processed in the correct order so as to, for example, define standard file extensions before defining file names.

While it would be simpler to just clear the variables, source the file (if found), and then populate any variables that were not defined, it wouldn't appropriately handle a conf file with errors.

I'm not really sure it's necessary to split the conf file loading into separate methods as I have done here, but it makes testing and maintenance easier.

Anyway, this is NOT READY FOR INTEGRATION as is. It definitely needs to be reworked, if it's necessary at all.

codewithmichael commented 9 years ago

Rebased for v0.1.2.