Last active
August 29, 2015 14:23
-
-
Save gullitmiranda/2fe8d9f1bc59a01cea63 to your computer and use it in GitHub Desktop.
`cli-router` help controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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