-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.js
executable file
·46 lines (36 loc) · 894 Bytes
/
cli.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
#!/usr/bin/env node
'use strict'
const mri = require('mri')
const pkg = require('./package.json')
const ui = require('.')
const argv = mri(process.argv.slice(2), {
boolean: ['help', 'h', 'version', 'v']
})
if (argv.help || argv.h) {
process.stdout.write(`
Usage:
leveldb-editor [--value-encoding <env>] <path-to-leveldb>
Options:
--value-encoding -e How the values are encoded in the db. Default: utf8
Examples:
leveldb-editor foo/bar/data.leveldb
\n`)
process.exit(0)
}
if (argv.version || argv.v) {
process.stdout.write(`leveldb-editor v${pkg.version}\n`)
process.exit(0)
}
const level = require('level')
const showError = (err) => {
console.error(err)
process.exit(1)
}
const path = argv._[0]
if (!path) showError('You must provide a path.')
// todo: indicate pending open
level(path, (err, db) => {
if (err) showError(err)
ui(db, path)
.catch(showError)
})