var pull = require('pull-stream') var paramap = require('pull-paramap') var u = require('./util') var cat = require('pull-cat') exports.help = ` Usage: git ssb named [name] Find repos by name Arguments: name search term to look for in names ` exports.fn = function (argv) { if (argv._.length !== 1) return u.help('named') var name = argv._[0] var searchRegexp = new RegExp(name) process.stderr.write('Searching...\r') u.getSbot(argv, function (err, sbot) { if (err) throw err pull( cat([ sbot.links2.read({query: [ {$filter: {rel: ['about', name]}, link: {$prefix: '%'}}, {$map: {about: 'dest', name: ['rel', 1]}}, ]}), sbot.links2.read({query: [ {$filter: {rel: ['about', {$gt: ''}]}}, {$map: {about: 'dest', name: ['rel', 1]}}, {$filter: {link: {$prefix: '%'}}} ]}), sbot.messagesByType('git-repo') ]), pull.filter(function (msgOrLink) { var c = msgOrLink.value && msgOrLink.value.content || msgOrLink return name === c.name || searchRegexp.test(c.name) }), paramap(function (msgOrLink, cb) { if (msgOrLink.link) u.getMsg(sbot, msgOrLink.link, cb) else cb(null, msgOrLink) }, 8), pull.filter(function (msg) { var c = msg.value && msg.value.content return c && c.type === 'git-repo' }), pull.map(function (msg) { var c = msg.value && msg.value.content || msg var key = c.about || msg.key return 'ssb://' + key + ' ' + c.name }), pull.unique(), pull.log(function (err) { if (err) throw err process.exit(0) }) ) }) }