Fix custom command not found when specifying different config dir
Resolves: #123
This commit is contained in:
1 parent
a47811d20f
commit
1362eb4cd9
1 file changed
+11
-2
@@ -15,22 +15,31 @@
|
|||||||
# along with GenieACS. If not, see <http://www.gnu.org/licenses/>.
|
# along with GenieACS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
###
|
###
|
||||||
|
|
||||||
|
path = require 'path'
|
||||||
config = require './config'
|
config = require './config'
|
||||||
common = require './common'
|
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) ->
|
exports.execute = (deviceId, command, callback) ->
|
||||||
args = command.split(/\s+/)
|
args = command.split(/\s+/)
|
||||||
f = args.shift()
|
f = args.shift()
|
||||||
c = args.shift()
|
c = args.shift()
|
||||||
|
|
||||||
file = require "../config/custom_commands/#{f}"
|
file = getFile(f)
|
||||||
file[c](deviceId, args.join(' '), callback)
|
file[c](deviceId, args.join(' '), callback)
|
||||||
|
|
||||||
|
|
||||||
exports.getFileCommands = (filename) ->
|
exports.getFileCommands = (filename) ->
|
||||||
commands = []
|
commands = []
|
||||||
f = require("../config/custom_commands/#{filename}")
|
f = getFile(filename)
|
||||||
for k,v of f
|
for k,v of f
|
||||||
commands.push(k)
|
commands.push(k)
|
||||||
return commands
|
return commands
|
||||||
|
|||||||
Reference in new issue
Block a user