-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
bin.js
51 lines (45 loc) · 1.19 KB
/
bin.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
const Client = require('ssb-client');
const manifest = require('./manifest');
const config = require('./config');
const lastArgv = process.argv[process.argv.length - 1];
if (lastArgv === 'start') {
require('./index');
} else if (lastArgv === 'check') {
// normal command:
// create a client connection to the server
var opts = {
manifest: manifest,
port: config.port,
host: config.host || 'localhost',
caps: config.caps,
key: config.key || config.keys.id,
};
// connect
Client(config.keys, opts, function(err1, rpc) {
if (err1) {
if (/could not connect/.test(err1.message)) {
console.error(
'Error: Could not connect to ssb-server ' +
opts.host +
':' +
opts.port,
);
console.error('Use the "start" command to start it.');
console.error('Use --verbose option to see full error');
if (config.verbose) throw err1;
process.exit(1);
}
throw err1;
}
rpc.whoami((err2, x) => {
if (err2) {
console.error(err2);
process.exit(1);
} else {
console.log(x.id);
process.exit(0);
}
});
});
}