Skip to content

Commit

Permalink
feat(CLI): add a simple cli tool
Browse files Browse the repository at this point in the history
  • Loading branch information
tivie committed Jul 13, 2015
1 parent ba7eb7e commit f6a33e4
Show file tree
Hide file tree
Showing 23 changed files with 412 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
.DS_Store
node_modules
npm-debug.log
localtest.html
/*.test.*
2 changes: 2 additions & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Gruntfile.js
dist/**/*.js
build/**/*.js
src/options.js
bin/*
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = function (grunt) {
},
dist: {
src: [
'src/options.js',
'src/showdown.js',
'src/helpers.js',
'src/converter.js',
Expand Down
2 changes: 2 additions & 0 deletions bin/showdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('../src/cli/cli');
135 changes: 105 additions & 30 deletions dist/showdown.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/showdown.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/showdown.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js.map

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"test": "grunt test"
},
"bin": {
"showdown": "src/cli.js"
"showdown": "bin/showdown.js"
},
"devDependencies": {
"chai": "^1.10.0",
Expand All @@ -53,5 +53,8 @@
"quiet-grunt": "^0.2.3",
"sinon": "^1.14.1",
"source-map-support": "^0.2.9"
},
"dependencies": {
"yargs": "^3.15.0"
}
}
23 changes: 0 additions & 23 deletions src/cli.js

This file was deleted.

30 changes: 30 additions & 0 deletions src/cli/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

var version = require('../../package.json').version,
yargs = require('yargs');

yargs
.version(version, 'v')
.alias('v', 'version')
.option('h', {
alias: 'help',
description: 'Show help'
})
.usage('Usage: showdown <command> [options]')
.demand(1, 'You must provide a valid command')
.command('makehtml', 'Converts markdown into html')
.example('showdown makehtml -i foo.md -o bar.html', 'Converts \'foo.md\' to \'bar.html\'')
.wrap(yargs.terminalWidth());

var argv = yargs.argv,
command = argv._[0];
if (command === 'makehtml') {
require('./makehtml.cmd.js').run();
} else {
yargs.showHelp();
}

if (argv.help) {
yargs.showHelp();
}
process.exit(0);
6 changes: 6 additions & 0 deletions src/cli/errorexit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = exports = function errorExit(e) {
'use strict';
console.error('ERROR: ' + e.message);
console.error('Run \'showdown <command> -h\' for help');
process.exit(1);
};
Loading

0 comments on commit f6a33e4

Please sign in to comment.