Skip to content
Snippets Groups Projects
Commit b7fe37de authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Removed required argument for config, now handled by conversions, not a option means required

parent e3964450
No related branches found
No related tags found
No related merge requests found
...@@ -133,11 +133,12 @@ class Config(var map: Map[String, Any]) extends Logging { ...@@ -133,11 +133,12 @@ class Config(var map: Map[String, Any]) extends Logging {
*/ */
protected[config] def apply(module: String, path: List[String], key: String, default: Any = null, freeVar: Boolean = true): ConfigValue = { protected[config] def apply(module: String, path: List[String], key: String, default: Any = null, freeVar: Boolean = true): ConfigValue = {
val requestedIndex = ConfigValueIndex(module, path, key, freeVar) val requestedIndex = ConfigValueIndex(module, path, key, freeVar)
if (contains(requestedIndex)) return foundCache(requestedIndex) if (contains(requestedIndex)) foundCache(requestedIndex)
else if (default != null) { else if (default != null) {
defaultCache += (requestedIndex -> ConfigValue(requestedIndex, null, default, freeVar)) defaultCache += (requestedIndex -> ConfigValue(requestedIndex, null, default, freeVar))
return defaultCache(requestedIndex) defaultCache(requestedIndex)
} else throw new IllegalStateException("Value in config could not be found but it seems required, index: " + requestedIndex) } else ConfigValue(requestedIndex, null, null, freeVar)
//else throw new IllegalStateException("Value in config could not be found but it seems required, index: " + requestedIndex)
} }
def writeReport(id: String, directory: String): Unit = { def writeReport(id: String, directory: String): Unit = {
......
...@@ -79,7 +79,6 @@ trait Configurable extends ImplicitConversions { ...@@ -79,7 +79,6 @@ trait Configurable extends ImplicitConversions {
* @param key Name of value * @param key Name of value
* @param default Default value if not found * @param default Default value if not found
* @param submodule Adds to the path * @param submodule Adds to the path
* @param required Default false, if true and value is not found this function will raise an exception
* @param freeVar Default true, if set false value must exist in module * @param freeVar Default true, if set false value must exist in module
* @param sample Default null, when set path is prefixed with "samples" -> "sampleID" * @param sample Default null, when set path is prefixed with "samples" -> "sampleID"
* @param library Default null, when set path is prefixed with "libraries" -> "libraryID" * @param library Default null, when set path is prefixed with "libraries" -> "libraryID"
...@@ -88,7 +87,6 @@ trait Configurable extends ImplicitConversions { ...@@ -88,7 +87,6 @@ trait Configurable extends ImplicitConversions {
def apply(key: String, def apply(key: String,
default: Any = null, default: Any = null,
submodule: String = null, submodule: String = null,
required: Boolean = false,
freeVar: Boolean = true, freeVar: Boolean = true,
sample: String = null, sample: String = null,
library: String = null): ConfigValue = { library: String = null): ConfigValue = {
...@@ -100,14 +98,8 @@ trait Configurable extends ImplicitConversions { ...@@ -100,14 +98,8 @@ trait Configurable extends ImplicitConversions {
val value = Config.getValueFromMap(defaults.toMap, ConfigValueIndex(m, p, key, freeVar)) val value = Config.getValueFromMap(defaults.toMap, ConfigValueIndex(m, p, key, freeVar))
if (value.isDefined) value.get.value else default if (value.isDefined) value.get.value else default
} }
if (!contains(key, submodule, freeVar, sample = s, library = l) && d == null) { if (d == null) Config.global(m, p, key, freeVar = freeVar)
if (required) { else Config.global(m, p, key, d, freeVar)
Logging.logger.error("Value in config could not be found but it is required, key: " + key + " module: " + m + " path: " + p)
throw new IllegalStateException("Value in config could not be found but it is required, key: " + key + " module: " + m + " path: " + p)
} else return null
}
if (d == null) return Config.global(m, p, key, freeVar = freeVar)
else return Config.global(m, p, key, d, freeVar)
} }
/** /**
......
...@@ -332,7 +332,9 @@ object ConfigUtils extends Logging { ...@@ -332,7 +332,9 @@ object ConfigUtils extends Logging {
private def requiredValue(value: ConfigValue): Unit = { private def requiredValue(value: ConfigValue): Unit = {
if (!valueExists(value)) if (!valueExists(value))
throw new IllegalStateException("Value does not exist but is required, key: '" + value.requestIndex.key + "'") throw new IllegalStateException("Value does not exist but is required, key: " + value.requestIndex.key +
" module: " + value.requestIndex.module +
(if (value.requestIndex.path != Nil) " path: " + value.requestIndex.path.mkString("->") else ""))
} }
private def valueExists(value: ConfigValue): Boolean = { private def valueExists(value: ConfigValue): Boolean = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment