nodejs-bash-completion/log

81 lines
1.8 KiB
JavaScript
Executable File

#!/usr/bin/env node
const This = require('./this');
const util = require('util');
class Log extends This {
constructor() {
super();
this.version = '0.0.1';
this.description = 'Helper script for building log messages';
super.init(); // initialize commander with overridden version and description
}
echo(str) {
console.log(str);
}
success(str) {
console.log(this._echoInGreen(str));
}
info(str) {
console.log(`[INFO] ${str}`);
}
warn(str) {
console.warn(`[WARN] ${this._echoInYellow(str)}`);
}
error(str) {
console.error(`[ERR] ${this._echoInRed(str)}`);
}
start() {
this.program.command('echo')
.argument('<message>')
.action(message => {
this.echo(message);
});
this.program.command('success')
.argument('<message>')
.action(message => {
this.success(message);
});
this.program.command('info')
.argument('<message>')
.action(message => {
this.info(message);
});
this.program.command('warn')
.argument('<message>')
.action(message => {
this.warn(message);
});
this.program.command('error')
.argument('<message>')
.action(message => {
this.error(message);
});
this.program.parse();
if (Object.keys(this.program.opts()).length || this.program.args.length) {
//// Debugging commander options and arguments
const opts = util.inspect(this.program.opts(), { depth: null, colors: true, showHidden: true });
const args = util.inspect(this.program.args, { depth: null, colors: true, showHidden: true });
//this.echo(`Options: ${opts}`);
//this.echo(`Remaining arguments: ${args}`);
} else {
this.program.outputHelp();
}
}
}
// main
const log = new Log();
log.start();