diff --git a/bin/marky-markdown.js b/bin/marky-markdown.js index eb0570a..f9799a6 100755 --- a/bin/marky-markdown.js +++ b/bin/marky-markdown.js @@ -2,15 +2,47 @@ var fs = require('fs') var path = require('path') var marky = require('..') +var information = require('../marky.json') -if (process.argv.length < 3) { - console.log('Usage:\n\nmarky-markdown some.md > some.html') +var executable = process.argv[0] +var script = process.argv[1] +var parameters = process.argv.slice(2) + +function printHelp () { + console.log('Usage: marky-markdown [filename]') + console.log('') + console.log('Options: ') + console.log(' -h, --help show this help message') + console.log(' -v, --version print the marky-markdown version') + console.log('') + console.log('Example: `marky-markdown readme.md`') +} + +function help () { + if (parameters[0] === '-h' || parameters[0] === '--help') { + printHelp() + process.exit() + } +} + +function version () { + if (parameters[0] === '-V' || parameters[0] === '--version') { + console.log(information.version) + process.exit() + } +} + +if (parameters.length === 0) { + printHelp() process.exit() } -var filePath = path.resolve(process.cwd(), process.argv[2]) +help() +version() + +var filename = path.resolve(process.cwd(), argv[0]) -fs.readFile(filePath, function (err, data) { +fs.readFile(filename, function (err, data) { if (err) throw err var html = marky(data.toString()) process.stdout.write(html)