git ssb

39+

cel / git-ssb



Tree: 9879cbb757d4bcde4e81cb784c35900a61a22bd6

Files: 9879cbb757d4bcde4e81cb784c35900a61a22bd6 / lib / named.js

1713 bytesRaw
1var pull = require('pull-stream')
2var paramap = require('pull-paramap')
3var u = require('./util')
4var cat = require('pull-cat')
5
6exports.help = `
7Usage: git ssb named [name]
8
9 Find repos by name
10
11Arguments:
12 name search term to look for in names
13`
14
15exports.fn = function (argv) {
16 if (argv._.length !== 1) return u.help('named')
17
18 var name = argv._[0]
19 var searchRegexp = new RegExp(name)
20 process.stderr.write('Searching...\r')
21
22 u.getSbot(argv, function (err, sbot) {
23 if (err) throw err
24 pull(
25 cat([
26 sbot.links2.read({query: [
27 {$filter: {rel: ['about', name]}, link: {$prefix: '%'}},
28 {$map: {about: 'dest', name: ['rel', 1]}},
29 ]}),
30 sbot.links2.read({query: [
31 {$filter: {rel: ['about', {$gt: ''}]}},
32 {$map: {about: 'dest', name: ['rel', 1]}},
33 {$filter: {link: {$prefix: '%'}}}
34 ]}),
35 sbot.messagesByType('git-repo')
36 ]),
37 pull.filter(function (msgOrLink) {
38 var c = msgOrLink.value && msgOrLink.value.content || msgOrLink
39 return name === c.name || searchRegexp.test(c.name)
40 }),
41 paramap(function (msgOrLink, cb) {
42 if (msgOrLink.link) u.getMsg(sbot, msgOrLink.link, cb)
43 else cb(null, msgOrLink)
44 }, 8),
45 pull.filter(function (msg) {
46 var c = msg.value && msg.value.content
47 return c && c.type === 'git-repo'
48 }),
49 pull.map(function (msg) {
50 var c = msg.value && msg.value.content || msg
51 var key = c.about || msg.key
52 return 'ssb://' + key + ' ' + c.name
53 }),
54 pull.unique(),
55 pull.log(function (err) {
56 if (err) throw err
57 process.exit(0)
58 })
59 )
60 })
61}
62

Built with git-ssb-web