-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·84 lines (77 loc) · 1.87 KB
/
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
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
82
83
84
#!/usr/bin/env node
const commandLineArgs = require("command-line-args");
const commandLineUsage = require("command-line-usage");
const mongoRanger = require("./mongo-ranger");
const optionDefinitions = [
{
name: "host",
type: String,
defaultOption: true,
description: "server to connect to, SRV string can be used"
},
{
name: "port",
alias: "p",
type: Number,
description: "port to conect to"
},
{
name: "help",
alias: "h",
type: Boolean,
description: "show this help page"
},
{
name: "debug",
type: Boolean,
description: "show debug logs"
}
];
const usage = [
{
header: "mongo-ranger",
content: "A MongoDB data browser for the console."
},
{
header: "Synopsis",
content: [
"$ mongo-ranger [{underline connection-string}]",
"$ mongo-ranger [{bold --host} {underline host}] [{bold --port} {underline port}]",
"$ mongo-ranger {bold --help}"
]
},
{
header: "Controls",
content: [
"- Browse data using the arrow keys or hjkl (vim-like controls)",
"- Use / to search the selected column (does not query db)",
"- Use : to type a MongoDB query for the selected collection",
"- Move forward on an individual field to edit",
"- Push i to insert a new document or field",
"- Push d to delete a document or field",
"- Push r to reload the current collection"
]
},
{
header: "Options",
optionList: optionDefinitions
}
];
let options;
try {
options = commandLineArgs(optionDefinitions);
} catch (e) {
// invalid options provided
console.log(commandLineUsage(usage));
return;
}
if (options.help) {
console.log(commandLineUsage(usage));
return;
}
options.host = options.host || "mongodb://localhost";
options.port = options.port || "";
mongoRanger(options).catch(e => {
console.error(e);
return process.exit(1);
});