Fix custom command not found when specifying different config dir

Resolves: #123
This commit is contained in:
Zaid Abdulla committed 2015-12-20 02:06:51 +03:00
1 parent a47811d20f
commit 1362eb4cd9
1 file changed
+11 -2
+11 -2
View File
@@ -15,22 +15,31 @@
# along with GenieACS. If not, see <http://www.gnu.org/licenses/>.
###
path = require 'path'
config = require './config'
common = require './common'
FILES = {}
getFile = (filename) ->
if filename not of FILES
FILES[filename] = require(path.resolve(config.get('CONFIG_DIR'), "custom_commands/#{filename}"))
return FILES[filename]
exports.execute = (deviceId, command, callback) ->
args = command.split(/\s+/)
f = args.shift()
c = args.shift()
file = require "../config/custom_commands/#{f}"
file = getFile(f)
file[c](deviceId, args.join(' '), callback)
exports.getFileCommands = (filename) ->
commands = []
f = require("../config/custom_commands/#{filename}")
f = getFile(filename)
for k,v of f
commands.push(k)
return commands