Skip to content

Instantly share code, notes, and snippets.

@dominictarr
Created December 2, 2019 08:12

Revisions

  1. dominictarr created this gist Dec 2, 2019.
    32 changes: 32 additions & 0 deletions aggregate-help.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    module.exports = function (sbot, cb) {
    var help = null
    sbot.help(function (err, data) {
    if(!data.type) data.type = 'group'
    help = data
    var keys = Object.keys(sbot)
    var n = keys.length + 1
    keys.forEach(function (key) {
    if(sbot[key] && 'function' === typeof sbot[key].help)
    sbot[key].help(function (err, data) {
    if(!data.type) data.type = 'group'
    help.commands[key] = data
    done()
    })
    else --n
    })
    done()
    function done (err) {
    if(--n) return
    cb(null, help)
    }
    })
    }

    if(!module.parent)
    require('ssb-client')(function (err, rpc) {
    if(err) throw err
    module.exports(rpc, function (err, data) {
    console.log(JSON.stringify(data, null, 2))
    rpc.close()
    })
    })