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:
Conf file not found
Conf file found but missing some expected variables
Conf file found but corrupt, has errors, or exits unexpectedly
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.
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.