MXS-1300: Refactor the way maxctrl is invoked
Making the invocation explicit should allow testing without actually starting the process fromt the command line. Also returning a promise allows chaining of commands for testing and verification.
This commit is contained in:
@ -160,6 +160,9 @@ module.exports = function() {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
logError(JSON.stringify(err, null, 4))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateValue = function(resource, key, value) {
|
this.updateValue = function(resource, key, value) {
|
||||||
|
@ -11,10 +11,24 @@
|
|||||||
* Public License.
|
* Public License.
|
||||||
*/
|
*/
|
||||||
require('./common.js')()
|
require('./common.js')()
|
||||||
|
var fs = require('fs')
|
||||||
const maxctrl_version = '1.0.0';
|
const maxctrl_version = '1.0.0';
|
||||||
|
|
||||||
module.exports = function(argv) {
|
module.exports = function(argv) {
|
||||||
|
|
||||||
|
// Mangle the arguments if we are being called from the command line
|
||||||
|
if (argv[0] == process.execPath) {
|
||||||
|
argv.shift()
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
while (argv.length > 0) {
|
||||||
|
fs.accessSync(argv[0])
|
||||||
|
argv.shift()
|
||||||
|
}
|
||||||
|
} catch (err) { }
|
||||||
|
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
program
|
program
|
||||||
.version(maxctrl_version)
|
.version(maxctrl_version)
|
||||||
.group(['u', 'p', 'h', 's', 't'], 'Global Options:')
|
.group(['u', 'p', 'h', 's', 't'], 'Global Options:')
|
||||||
@ -71,6 +85,12 @@ module.exports = function(argv) {
|
|||||||
.command('*', 'the default command', {}, () => {
|
.command('*', 'the default command', {}, () => {
|
||||||
console.log('Unknown command. See output of `help` for a list of commands.')
|
console.log('Unknown command. See output of `help` for a list of commands.')
|
||||||
})
|
})
|
||||||
.parse(argv)
|
.parse(process.argv, function(err, argv, output) {
|
||||||
.argv
|
if (err) {
|
||||||
|
reject(output)
|
||||||
|
} else {
|
||||||
|
resolve(output);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user