diff --git a/bin/wtf.js b/bin/wtf.js new file mode 100755 index 0000000..490a9ae --- /dev/null +++ b/bin/wtf.js @@ -0,0 +1,35 @@ +#!/usr/bin/env node +var wtf = require('../src/index'); +var args = process.argv.slice(2, process.argv.length); + +var modes = { + '--json': 'json', + '--plaintext': 'plaintext', + '--html': 'html', + '--markdown': 'markdown', + '--latex': 'latex', +}; +var mode = 'json'; +args = args.filter((arg) => { + if (modes.hasOwnProperty(arg) === true) { + mode = modes[arg]; + return false; + } + return true; +}); + +var title = args.join(' '); +if (!title) { + throw new Error('Usage: wtf_wikipedia Toronto Blue Jays --plaintext'); +} + +wtf.fetch(title, 'en', function (err, doc) { + if (err) { + console.error(err); + } + if (mode === 'json') { + console.log(JSON.stringify(doc[mode](), null, 0)); + } else { + console.log(doc[mode]()); + } +}); diff --git a/package.json b/package.json index bd42616..f0825fd 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "wtf_fetch", "description": "Fetch Wiki markdown from MediaWiki", - "version": "1.0.5", + "version": "1.1.0", "author": "Based on Work of Spencer Kelly ", "repository": { "type": "git",