From 2d6cd1e9086b275d629f3de4b6ed22317ba5cfe9 Mon Sep 17 00:00:00 2001 From: Estevao Soares dos Santos Date: Sun, 8 Jan 2017 20:02:42 +0000 Subject: [PATCH] feat(CLI:flavor): add flavor option to CLI Add the option to pass a flavor preset to CLI. Ex: `showdown makehtml --flavor="github"` --- package.json | 2 +- src/cli/cli.js | 5 ++--- src/cli/makehtml.cmd.js | 21 ++++++++++++++++----- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 81d11a3..7dea516 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,6 @@ "source-map-support": "^0.2.9" }, "dependencies": { - "yargs": "^3.15.0" + "yargs": "^6.6.0" } } diff --git a/src/cli/cli.js b/src/cli/cli.js index 7cd8dc4..62fa0f7 100644 --- a/src/cli/cli.js +++ b/src/cli/cli.js @@ -1,10 +1,9 @@ 'use strict'; -var version = require('../../package.json').version, - yargs = require('yargs'); +var yargs = require('yargs'); yargs - .version(version, 'v') + .version() .alias('v', 'version') .option('h', { alias: 'help', diff --git a/src/cli/makehtml.cmd.js b/src/cli/makehtml.cmd.js index acaf359..e688381 100644 --- a/src/cli/makehtml.cmd.js +++ b/src/cli/makehtml.cmd.js @@ -7,7 +7,12 @@ yargs.reset() .usage('Usage: showdown makehtml [options]') .example('showdown makehtml -i', 'Reads from stdin and outputs to stdout') .example('showdown makehtml -i foo.md -o bar.html', 'Reads \'foo.md\' and writes to \'bar.html\'') - //.demand(['i']) + .config('c') + .alias('c', 'config') + .help('h') + .alias('h', 'help') + .version() + .alias('v', 'version') .option('i', { alias : 'input', describe: 'Input source. Usually a md file. If omitted or empty, reads from stdin', @@ -34,10 +39,11 @@ yargs.reset() describe: 'Load the specified extensions. Should be valid paths to node compatible extensions', type: 'array' }) - .config('c') - .alias('c', 'config') - .help('h') - .alias('h', 'help'); + .option('p', { + alias : 'flavor', + describe: 'Run with a predetermined flavor of options. Default is vanilla', + type: 'string' + }); yargs.options(showdown.getDefaultOptions(false)); argv = yargs.argv; @@ -81,6 +87,11 @@ function run() { } } + // Load flavor + if (argv.p) { + converter.setFlavor(argv.p); + } + // parse and convert file output = converter.makeHtml(input);