lib/config.js
function getSetting (config, section, setting, required, readFromFile,
                     configPath) {
  if (typeof (required) === 'undefined') { required = true }
  if (typeof (configPath) === 'undefined') { configPath = null }

  if (!config[section]) {
    if (required) {
      throw new DxlError('Required section not found in config: ' +
        section)
    } else {
      return null
    }
  }

  if (!config[section][setting]) {
    if (required) {
      throw new DxlError('Required setting not found in config: ' +
        setting)
    } else {
      return null
    }
  }

  var value = config[section][setting]

  if (readFromFile) {
    var fileToRead = util.getConfigFilePath(configPath, value)
    if (fs.existsSync(fileToRead)) {
      try {
        value = fs.readFileSync(fileToRead)
      } catch (err) {
        throw new DxlError('Unable to read file for ' + setting + ': ' +
          err.message)
      }
    } else {
      throw new DxlError('Unable to locate file for ' + setting +
        ': ' + value)
    }
  }

  return value
}
function getSetting (config, section, setting, required, readFromFile,
                     configPath) {
  if (typeof (required) === 'undefined') { required = true }
  if (typeof (configPath) === 'undefined') { configPath = null }

  if (!config[section]) {
    if (required) {
      throw new DxlError('Required section not found in config: ' +
        section)
    } else {
      return null
    }
  }

  if (!config[section][setting]) {
    if (required) {
      throw new DxlError('Required setting not found in config: ' +
        setting)
    } else {
      return null
    }
  }

  var value = config[section][setting]

  if (readFromFile) {
    var fileToRead = util.getConfigFilePath(configPath, value)
    if (fs.existsSync(fileToRead)) {
      try {
        value = fs.readFileSync(fileToRead)
      } catch (err) {
        throw new DxlError('Unable to read file for ' + setting + ': ' +
          err.message)
      }
    } else {
      throw new DxlError('Unable to locate file for ' + setting +
        ': ' + value)
    }
  }

  return value
}
function getSetting ( config , section , setting , required , readFromFile , configPath ) { if ( typeof ( required ) === 'undefined' ) { required = true } if ( typeof ( configPath ) === 'undefined' ) { configPath = null } if ( ! config [ section ] ) { if ( required ) { throw new DxlError ( 'Required section not found in config: ' + section ) } else { return null } } if ( ! config [ section ] [ setting ] ) { if ( required ) { throw new DxlError ( 'Required setting not found in config: ' + setting ) } else { return null } } var value = config [ section ] [ setting ] if ( readFromFile ) { var fileToRead = util . getConfigFilePath ( configPath , value ) if ( fs . existsSync ( fileToRead ) ) { try { value = fs . readFileSync ( fileToRead ) } catch ( err ) { throw new DxlError ( 'Unable to read file for ' + setting + ': ' + err . message ) } } else { throw new DxlError ( 'Unable to locate file for ' + setting + ': ' + value ) } } return value }
Get the value for a setting from a configuration file.
@private
@param {Object} config - Object representation of a config file where each
key corresponds to a section or setting name and each value corresponds
to the contents of the section or the value for a setting, respectively.
@param {String} section - Name of the configuration section in which the
setting resides.
@param {String} setting - Name of the setting whose value should be
obtained.
@param {Boolean} [required=true] - Whether or not the setting is required
to exist in the configuration file. If _true_ and the setting cannot be
found, a {@link DxlError} is thrown.
@param {Boolean} [readFromFile=false] - Whether or not to try to treat the
value of setting as a file whose contents should be read and returned as
the value for the setting.
@param {String} [configPath=null] - Directory path in which the
configuration file should reside.
@returns {Object} Value for the setting.
@throws {DxlError} If the setting is required but cannot be found or if
the value should be read from a file but a problem occurs in reading
the file - for example, if the file cannot be found.
Get the value for a setting from a configuration file .