Skip to content

Instantly share code, notes, and snippets.

@gullitmiranda
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save gullitmiranda/2fe8d9f1bc59a01cea63 to your computer and use it in GitHub Desktop.

Select an option

Save gullitmiranda/2fe8d9f1bc59a01cea63 to your computer and use it in GitHub Desktop.
`cli-router` help controller
// JS usando ES6
var chalk = require('chalk');
var CliControllers = require('cli-router').CliControllers;
class Help extends CliControllers.Help {
index(params, cli) {
var usage = super.index(params, cli);
usage = this.colorizeSections(params, usage);
console.log(usage);
return 0;
}
colorizeSections(params, usage) {
_.map(this.sections, (section) => {
var regex = new RegExp(`^(${section}:)`, 'gmi');
var match = regex.match(usage);
if (match) {
usage = usage.replace(regex, chalk.blue(`${match[1]}`));
}
});
return usage;
}
}
module.exports = Help;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment