-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.js
81 lines (66 loc) · 2.4 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// ---------------------------------------------------------------------------------------------------------------------
// A simple configuration file for the server.
//
// @module config.js
// ---------------------------------------------------------------------------------------------------------------------
var path = require('path');
var _ = require('lodash');
// ---------------------------------------------------------------------------------------------------------------------
module.exports = {
DEBUG: parseBool(process.env.DEBUG, true),
logLevel: process.env.LOG_LEVEL || 'DEBUG',
port: 8008,
rethinkdb: {
host: 'localhost',
port: 28015,
db: 'rfi_mmorpg'
}
}; // end exports
// ---------------------------------------------------------------------------------------------------------------------
// Parse command-line options.
var argv = require('minimist')(process.argv.slice(2), { alias: { help: 'h' }, boolean: true });
if(argv.help)
{
var e = console.error.bind(console);
e('');
e(' Usage: %s [options]', path.basename(process.argv[1]));
e('');
e(' ' + GLOBAL.programDesc);
e('');
e(' Options:');
e('');
e(' -h, --help output usage information');
e('');
e(' --<config.option>=<value> set configuration option to <value>');
e(' --<config.option> set configuration option to `true`');
e('');
// If another module has registered extra lines for the help message, display them.
if(GLOBAL.extraHelp)
{
GLOBAL.extraHelp.forEach(function(extraHelpLine)
{
e(extraHelpLine);
});
e('');
} // end if
process.exit(1);
} // end if
_.merge(module.exports, _.omit(argv, '_'));
// ---------------------------------------------------------------------------------------------------------------------
// Parse a string as a boolean. (used to support boolean flags in environment variables)
function parseBool(boolString, defaultValue)
{
switch((boolString || '').toLowerCase())
{
case '0':
case 'false':
case 'off':
case 'no':
return false;
case '':
return defaultValue;
default:
return true;
} // end switch
} // end parseBool
// ---------------------------------------------------------------------------------------------------------------------