Permalink
Browse files

Write config get options documentation

  • Loading branch information...
1 parent d3390fd commit e357a35f56cd0a52e079127fbadb9e033bc18435 Matt Sergeant committed Feb 5, 2014
Showing with 34 additions and 4 deletions.
  1. +16 −3 config.js
  2. +18 −1 docs/Config.md
View
@@ -7,11 +7,24 @@ var config = exports;
var config_path = process.env.HARAKA ? path.join(process.env.HARAKA, 'config') : path.join(__dirname, './config');
+/* Ways this can be called:
+config.get('thing');
+config.get('thing', type);
+config.get('thing', cb);
+config.get('thing', type, cb);
+config.get('thing', type, options);
+config.get('thing', type, cb, options);
+*/
config.get = function(name, type, cb, options) {
- if (type === 'nolog') {
- type = arguments[2]; // deprecated - TODO: remove later
+ if (typeof type == 'function') {
+ options = cb;
+ cb = type;
+ type = 'value';
+ }
+ if (typeof cb != 'function') {
+ options = cb;
+ cb = null;
}
-
type = type || 'value';
var full_path = path.resolve(config_path, name);
var results = configloader.read_config(full_path, type, cb, options);
View
@@ -7,7 +7,7 @@ of configuration files.
The API is fairly simple:
// From within a plugin:
- var config_item = this.config.get(name, [type='value'], [callback]);
+ var config_item = this.config.get(name, [type='value'], [callback], [options]);
Where type can be one of:
@@ -31,6 +31,8 @@ respectively then the `type` parameter can be left off.
You can optionally pass in a callback function which will be called whenever
an update is detected on the file.
+For ini files, an `options` object is allowed.
+
File Formats
============
@@ -66,9 +68,24 @@ That produces the following Javascript object:
The key point there is that items before any [section] marker go in the "main"
section.
+Note that there is some auto-conversion of values on the right hand side of
+the equals: integers are converted to integers, floats are converted to
+floats.
+
The key=value pairs also support continuation lines using the
backslash "\" character.
+The `options` object allows you to specify which keys are boolean:
+
+ { booleans: ['reject','some_true_value'] }
+
+This ensures these values are converted to true Javascript booleans when parsed,
+and supports the following options for boolean values:
+
+ true, yes, ok, enabled, on, 1
+
+Anything else is treated as false.
+
Flat Files
----------

0 comments on commit e357a35

Please sign in to comment.