MXS-1300: Make MaxCtrl more like a library
All invocations into the common helper functions are now done through the `maxctrl` function. This allows the program arguments to be passed to the core as a parameter instead of reading them from global variables. This helps with the implicit initialization that was done when the yargs library was required which caused duplicated output. Refactored the core functions so that they only process the argument vector. The parsing of the argument vector is done in maxctrl.js where it is more appropriate.
This commit is contained in:
@ -20,22 +20,24 @@ exports.builder = function(yargs) {
|
||||
.command('command <module> <command> [parameters...]', 'Call a module command', {}, function(argv) {
|
||||
|
||||
// First we have to find the correct method to use
|
||||
doRequest('maxscale/modules/' + argv.module + '/', function(resp) {
|
||||
maxctrl(argv)
|
||||
.doRequest('maxscale/modules/' + argv.module + '/', function(resp) {
|
||||
|
||||
// A GET request will return the correct error if the command is not found
|
||||
var verb = 'GET'
|
||||
// A GET request will return the correct error if the command is not found
|
||||
var verb = 'GET'
|
||||
|
||||
resp.data.attributes.commands.forEach(function(i) {
|
||||
if (i.id == argv.command) {
|
||||
verb = i.attributes.method;
|
||||
}
|
||||
resp.data.attributes.commands.forEach(function(i) {
|
||||
if (i.id == argv.command) {
|
||||
verb = i.attributes.method;
|
||||
}
|
||||
})
|
||||
|
||||
maxctrl
|
||||
.doRequest('maxscale/modules/' + argv.module + '/' + argv.command + '?' + argv.parameters.join('&'),
|
||||
function(resp) {
|
||||
console.log(JSON.stringify(resp, null, 4))
|
||||
}, { method: verb })
|
||||
})
|
||||
|
||||
doRequest('maxscale/modules/' + argv.module + '/' + argv.command + '?' + argv.parameters.join('&'),
|
||||
function(resp) {
|
||||
console.log(JSON.stringify(resp, null, 4))
|
||||
}, { method: verb })
|
||||
})
|
||||
})
|
||||
.usage('Usage: call <command>')
|
||||
.help()
|
||||
|
||||
Reference in New Issue
Block a user