-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·51 lines (40 loc) · 988 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
47
48
49
50
51
#!/usr/bin/env node
'use strict'
const mri = require('mri')
const envPaths = require('env-paths')
const pkg = require('./package.json')
const argv = mri(process.argv.slice(2), {
boolean: ['help', 'h', 'version', 'v']
})
const defaultStorage = envPaths(pkg.name, {suffix: ''}).data
if (argv.help || argv.h) {
process.stdout.write(`
Usage:
hyper-chat <name> [key]
Options:
--storage -s Where to store the data.
Default: ${defaultStorage}
\n`)
process.exit(0)
}
if (argv.version || argv.v) {
process.stdout.write(`hyper-chat v${pkg.version}\n`)
process.exit(0)
}
const catNames = require('cat-names')
const openChat = require('.')
const showError = (err) => {
console.error(err)
process.exit(1)
}
const storage = argv.storage || argv.s || defaultStorage
const name = argv._[0] || catNames.random()
let key = argv._[1] || null
if (key) {
try {
key = Buffer.from(key, 'hex')
} catch (err) {
showError(err)
}
}
openChat(storage, key, name)