jmms
Version:
Jmms cli tools, Jmms is a java meta-micro-service framework
61 lines (49 loc) • 1.27 kB
JavaScript
const _ = require('lodash');
const chalk = require('chalk');
const init = function (commander) {
commander.option('-d, --debug', 'show debug info');
const argv = commander.normalize(process.argv);
this.debugEnabled = commander.debug = argv.indexOf('-d') > -1 || argv.indexOf('--debug') > -1;
if (this.debugEnabled) {
debug('Debug logging is on');
}
return this;
};
const debug = function (msg) {
if (this.debugEnabled) {
console.log(`${chalk.blue('DEBUG!')} ${msg}`);
}
};
const isDebugEnabled = function() {
return this.debugEnabled;
}
const info = function (msg) {
console.info(msg);
};
const exec = function (cmd, args) {
var msg = cmd;
if(_.isArray(args)) {
msg = msg + ' ' + args.join(' ');
}
console.info(`\n${chalk.green.bold('[EXEC]')} -> ${msg}\n...\n`);
};
const warn = function (msg) {
console.info(`\n${chalk.yellow('WARN!')} ${msg}`);
};
const error = function (msg) {
console.error(`\n${chalk.red.bold('ERROR!')} ${chalk.red(msg)}`);
};
const success = function (msg) {
console.info(`\n${chalk.green.bold(msg)}\n`);
};
module.exports = {
init,
debug,
info,
exec,
warn,
error,
success,
chalk,
isDebugEnabled
};