-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathread.js
50 lines (43 loc) · 1.38 KB
/
read.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
#!/usr/bin/env node
import commandLineArgs from 'command-line-args';
import getUsage from 'command-line-usage';
import {inspect} from 'util';
const commandLineOptions = [
{name: 'path', alias: 'p', type: String, defaultOption: true,
description: 'The path in Firebase from which to read data. You can omit the leading slash.'},
{name: 'help', alias: 'h', type: Boolean,
description: 'Display these usage instructions.'}
];
const usageSpec = [
{header: 'Data readout tool',
content:
'Reads a given path from Firebase and prints the result, decrypting if necessary. ' +
'REVIEWABLE_FIREBASE_URL, REVIEWABLE_FIREBASE_CREDENTIALS_FILE, and ' +
'REVIEWABLE_ENCRYPTION_AES_KEY must be set.'
},
{header: 'Options', optionList: commandLineOptions}
];
const args = commandLineArgs(commandLineOptions);
if (args.help) {
console.log(getUsage(usageSpec));
process.exit(0);
}
for (const property of ['path']) {
if (!(property in args)) {
console.log('Missing required option: ' + property + '.');
process.exit(1);
}
}
async function read() {
await import('./lib/loadFirebase.js');
args.path = args.path.replace(/^\//, '');
const value = await db.child(args.path).get();
// console.log(inspect(value, {depth: null}));
console.log(JSON.stringify(value, null, 2));
}
read().then(() => {
process.exit(0);
}, e => {
console.log(e);
process.exit(1);
});