1 | _ = require('lodash')
|
2 | async = require('async')
|
3 | settings = require('./settings')
|
4 |
|
5 | exports.commands = []
|
6 | exports.globalOptions = []
|
7 | exports.permissions = {}
|
8 |
|
9 | exports.findCommandBySignature = (signature) ->
|
10 | return _.find exports.commands, (command) ->
|
11 | return command.signature.toString() is signature
|
12 |
|
13 | exports.getMatchCommand = (signature, callback) ->
|
14 |
|
15 |
|
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 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
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)
|