Commit 6a7f12faedfeb0912d99c14588d1deb6db8cecce
better usage
Michael Williams committed on 9/28/2018, 5:49:22 AMParent: 6c1d8164c0b4cb9773e04b28181209e711a096fd
Files changed
bin.js | changed mode from 100644 to 100755 |
bin.js | |||
---|---|---|---|
@@ -1,37 +1,47 @@ | |||
1 … | +#!/usr/bin/env node | ||
2 … | + | ||
1 | 3 … | var pull = require('pull-stream') | |
2 | 4 … | var Client = require('ssb-client') | |
3 | 5 … | var sort = require('ssb-sort') | |
4 | 6 … | var parallel = require('run-parallel') | |
5 | 7 … | ||
6 | 8 … | var rootMessageId = process.argv[2] | |
7 | 9 … | ||
8 | -Client(function (err, client) { | ||
9 | - if (err) throw err | ||
10 … | +if (rootMessageId == null) { | ||
11 … | + console.log('usage: ssb-reveal <rootMessageId>') | ||
12 … | +} else { | ||
13 … | + run() | ||
14 … | +} | ||
10 | 15 … | ||
11 | - parallel( | ||
12 | - [ | ||
13 | - cb => getMessage({ client, messageId: rootMessageId }, cb), | ||
14 | - cb => getThreadRepliesByRootId({ client, rootMessageId }, cb), | ||
15 | - cb => client.about.get(cb) | ||
16 | - ], | ||
17 | - function (err, [rootMessage, threadReplies, about]) { | ||
18 | - if (err) throw err | ||
16 … | +function run () { | ||
17 … | + Client(function (err, client) { | ||
18 … | + if (err) throw err | ||
19 | 19 … | ||
20 | - var thread = [rootMessage, ...threadReplies] | ||
21 | - thread.forEach(function (message, index) { | ||
22 | - if (index === 0) { | ||
23 | - console.log(`- ${formatMessageLink({ message, about })}`) | ||
24 | - } else { | ||
25 | - console.log(` - ${formatMessageLink({ message, about })}`) | ||
26 | - } | ||
27 | - }) | ||
20 … | + parallel( | ||
21 … | + [ | ||
22 … | + cb => getMessage({ client, messageId: rootMessageId }, cb), | ||
23 … | + cb => getThreadRepliesByRootId({ client, rootMessageId }, cb), | ||
24 … | + cb => client.about.get(cb) | ||
25 … | + ], | ||
26 … | + function (err, [rootMessage, threadReplies, about]) { | ||
27 … | + if (err) throw err | ||
28 | 28 … | ||
29 | - client.close() | ||
30 | - } | ||
31 | - ) | ||
32 | -}) | ||
29 … | + var thread = [rootMessage, ...threadReplies] | ||
30 … | + thread.forEach(function (message, index) { | ||
31 … | + if (index === 0) { | ||
32 … | + console.log(`- ${formatMessageLink({ message, about })}`) | ||
33 … | + } else { | ||
34 … | + console.log(` - ${formatMessageLink({ message, about })}`) | ||
35 … | + } | ||
36 … | + }) | ||
33 | 37 … | ||
38 … | + client.close() | ||
39 … | + } | ||
40 … | + ) | ||
41 … | + }) | ||
42 … | +} | ||
43 … | + | ||
34 | 44 … | function formatMessageLink ({ message, about }) { | |
35 | 45 … | var authorName = about[message.value.author]['name'][message.value.author][0] | |
36 | 46 … | var time = formatTimestamp(message.value.timestamp) | |
37 | 47 … | return `[${time} : ${authorName}](${message.key}?unbox=${message.value.unbox})` |
Built with git-ssb-web