UNPKG

1.13 kBtext/coffeescriptView Raw
1_ = require('lodash')
2async = require('async')
3settings = require('./settings')
4
5exports.commands = []
6exports.globalOptions = []
7exports.permissions = {}
8
9exports.findCommandBySignature = (signature) ->
10 return _.find exports.commands, (command) ->
11 return command.signature.toString() is signature
12
13exports.getMatchCommand = (signature, callback) ->
14
15 # Omit wildcard command from the check
16 commands = _.reject exports.commands, (command) ->
17 return command.isWildcard()
18
19 async.eachSeries commands, (command, done) ->
20 command.signature.matches signature, (result) ->
21 return done() if not result
22
23 # TODO: Breaking from the async look this way may
24 # cause a memory leak.
25 # One possible solution is to call done() with the result
26 # tricking async that is an error, and handle accordingly
27 # in the final callback. However the solution looks ugly.
28 # Search for alternatives
29 return callback(null, command)
30 , (error) ->
31 return callback(error) if error?
32
33 wildcardSignature = settings.signatures.wildcard
34 result = exports.findCommandBySignature(wildcardSignature)
35 return callback(null, result)