-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathindex.js
44 lines (35 loc) · 999 Bytes
/
index.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
var completion = require('./lib/completion');
var history = require('./lib/history');
var createREPL = require('./lib/repl');
var getDB = require('./lib/db');
var locate = require('./lib/location');
var cache = require('./lib/cache');
var cli = require('./lib/cli');
module.exports = function(args) {
//
// find where the location by examining the arguments
// and create an instance to work with.
//
locate(args);
var db = getDB(args);
//
// if any of these commands are specified as arguments
// than the program should not be run in REPL mode.
//
var cliCommands = [
'keys', 'values', 'get', 'match',
'put', 'del', 'createReadStream', 'batch'
];
var cliMode = Object.keys(args).some(function(cmd) {
return cliCommands.indexOf(cmd) > -1;
});
if (cliMode) {
return cli(db, args);
}
//
// create the instance of the repl and start it.
//
var repl = createREPL(db, args, cache);
history(repl, args);
completion(repl, cache);
};