forked from ipfs/js-ipfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathid.js
42 lines (34 loc) · 1003 Bytes
/
id.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
'use strict'
const parseDuration = require('parse-duration').default
module.exports = {
command: 'id',
describe: 'Shows IPFS Node ID info',
builder: {
format: {
alias: 'f',
type: 'string',
describe: 'Print Node ID info in the given format. Allowed tokens: <id> <aver> <pver> <pubkey> <addrs> <protocols>'
},
timeout: {
type: 'string',
coerce: parseDuration
}
},
async handler ({ ctx: { ipfs, print }, format, timeout }) {
const id = await ipfs.id({
timeout
})
if (format) {
print(format
.replace('<id>', id.id)
.replace('<aver>', id.agentVersion)
.replace('<pver>', id.protocolVersion)
.replace('<pubkey>', id.publicKey)
.replace('<addrs>', (id.addresses || []).map(addr => addr.toString()).join('\n'))
.replace('<protocols>', (id.protocols || []).map(protocol => protocol.toString()).join('\n'))
)
return
}
print(JSON.stringify(id, '', 2))
}
}