Skip to content

Commit

Permalink
feat(CLI): add -q (quiet) and -m (mute) mode to CLI
Browse files Browse the repository at this point in the history
-q supresses all normal messages from the output, but still reports errors.
-m mutes all messages, even errors.
  • Loading branch information
tivie committed Jan 9, 2017
1 parent 4d78633 commit f3b86f0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
12 changes: 12 additions & 0 deletions src/cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ yargs
alias: 'help',
description: 'Show help'
})
.option('q', {
alias: 'quiet',
description: 'Quiet mode. Only print errors',
type: 'boolean',
default: false
})
.option('m', {
alias: 'mute',
description: 'Mute mode. Does not print anything',
type: 'boolean',
default: false
})
.usage('Usage: showdown <command> [options]')
.demand(1, 'You must provide a valid command')
.command('makehtml', 'Converts markdown into html')
Expand Down
16 changes: 13 additions & 3 deletions src/cli/makehtml.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ yargs.reset()
alias : 'flavor',
describe: 'Run with a predetermined flavor of options. Default is vanilla',
type: 'string'
})
.option('q', {
alias: 'quiet',
description: 'Quiet mode. Only print errors',
type: 'boolean',
default: false
})
.option('m', {
alias: 'mute',
description: 'Mute mode. Does not print anything',
type: 'boolean',
default: false
});

// load showdown default options
Expand All @@ -70,7 +82,7 @@ function run() {
* MSG object
* @type {Messenger}
*/
messenger = new Messenger(msgMode),
messenger = new Messenger(msgMode, argv.q, argv.m),
read = (readMode === 'stdin') ? readFromStdIn : readFromFile,
write = (writeMode === 'stdout') ? writeToStdOut : writeToFile,
enc = argv.encoding || 'utf8',
Expand Down Expand Up @@ -106,8 +118,6 @@ function run() {
// write the output
messenger.printMsg('Writing data to ' + writeMode + '...');
write(html, append);

messenger.printMsg('\n');
messenger.okExit();

function parseOptions(flavor) {
Expand Down
5 changes: 3 additions & 2 deletions src/cli/messenger.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function Messenger(writeMode, supress, mute) {
'use strict';
writeMode = writeMode || 'stderr';
supress = !!supress;
mute = (!!supress || !!mute);
supress = (!!supress || !!mute);
mute = !!mute;
this._print = (writeMode === 'stdout') ? console.log : console.error;

this.errorExit = function (e) {
Expand All @@ -15,6 +15,7 @@ function Messenger(writeMode, supress, mute) {

this.okExit = function () {
if (!mute) {
this._print('\n');
this._print('DONE!');
}
process.exit(0);
Expand Down
2 changes: 1 addition & 1 deletion test/node/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('showdown cli', function () {
if (semver.gt(process.versions.node, '0.12.0')) {
var execSync = require('child_process').execSync;
it('basic stdin stdout', function () {
var otp = execSync(cmd + ' makehtml', {
var otp = execSync(cmd + ' makehtml -q', {
encoding: 'utf8',
input: '**foo**'
});
Expand Down

0 comments on commit f3b86f0

Please # to comment.