Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wtf.js added to bin because npm install wtf_fetch is complaining abou…
…t missing wtf.js in bin/
- Loading branch information
Engelbert Niehaus
committed
Apr 10, 2019
1 parent
cb2259b
commit 2da3753
Showing
2 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]()); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters