Skip to content

Commit

Permalink
🎨 add utilities to support verbose output
Browse files Browse the repository at this point in the history
refs #46
  • Loading branch information
acburdine committed Oct 17, 2016
1 parent a32b7d2 commit 596a668
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ function cli(args) {
cmdInstances[command].commander.help();
});

program.option('-V, --verbose', 'Enable verbose output');

program.parse(args);

if (!program.args.length) {
Expand Down
7 changes: 7 additions & 0 deletions lib/commands/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ module.exports = CoreObject.extend({
var self = this;

return function wrappedCommand() {
var last = require('lodash/last'),
options = last(arguments);

if (options.parent.verbose) {
self.ui.setVerbosity(true);
}

return Promise.resolve(self.execute.apply(self, arguments)).then(function success() {
// TODO: better cleanup
self.ui.success('Finished!');
Expand Down
11 changes: 10 additions & 1 deletion lib/ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ var chalk = require('chalk'),
defaultOptions = {
stdin: process.stdin,
stdout: process.stdout,
stderr: process.stderr
stderr: process.stderr,
verbose: false
};

UI = function UI(options) {
Expand Down Expand Up @@ -65,4 +66,12 @@ UI.prototype.fail = function error(message) {
return this.log(message, 'red');
};

UI.prototype.setVerbosity = function setVerbosity(verbose) {
this.verbose = !!verbose;
};

UI.prototype.isVerbose = function isVerbose() {
return this.verbose;
};

module.exports = UI;

0 comments on commit 596a668

Please sign in to comment.