From f3b86f06cce2707079f84bd21a2a23f66d445f82 Mon Sep 17 00:00:00 2001 From: Estevao Soares dos Santos Date: Mon, 9 Jan 2017 02:26:24 +0000 Subject: [PATCH] feat(CLI): add -q (quiet) and -m (mute) mode to CLI -q supresses all normal messages from the output, but still reports errors. -m mutes all messages, even errors. --- src/cli/cli.js | 12 ++++++++++++ src/cli/makehtml.cmd.js | 16 +++++++++++++--- src/cli/messenger.js | 5 +++-- test/node/cli.js | 2 +- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/cli/cli.js b/src/cli/cli.js index 74c14094..2ed59abf 100644 --- a/src/cli/cli.js +++ b/src/cli/cli.js @@ -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 [options]') .demand(1, 'You must provide a valid command') .command('makehtml', 'Converts markdown into html') diff --git a/src/cli/makehtml.cmd.js b/src/cli/makehtml.cmd.js index 1bc6e76e..85b94927 100644 --- a/src/cli/makehtml.cmd.js +++ b/src/cli/makehtml.cmd.js @@ -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 @@ -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', @@ -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) { diff --git a/src/cli/messenger.js b/src/cli/messenger.js index ad80bd5e..fc3fe5ab 100644 --- a/src/cli/messenger.js +++ b/src/cli/messenger.js @@ -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) { @@ -15,6 +15,7 @@ function Messenger(writeMode, supress, mute) { this.okExit = function () { if (!mute) { + this._print('\n'); this._print('DONE!'); } process.exit(0); diff --git a/test/node/cli.js b/test/node/cli.js index 36d82e3a..185b6359 100644 --- a/test/node/cli.js +++ b/test/node/cli.js @@ -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**' });