_ = require('underscore')
module.exports = (options = {}) ->This middleware registers new command ('help' by default) which shows the list of all possible commands.
_ = require('underscore')
module.exports = (options = {}) ->Middleware accepts following options:
options = _.defaults(options, { greeting: "Here are the commands you may use", helpString: "shows this help" command: "help", property: "autohelp" showOnUnknown: true}
)
install: (transit) ->
handler = (req, res) ->
toDescription = (h) ->
descr = [h.pattern]
if h.autohelp
descr.push " - "
descr.push h[options.property]
descr.join ""
help = [options.greeting + ": "].concat(req.handlers.map(toDescription).filter(_.identity)).join("\n * ")
res.sendBack help
transit.receive options.command, autohelp: options.helpString, handler
transit.receive handler if options.showOnUnknown