Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Add --stdin and --stdin-filename CLI options
Browse files Browse the repository at this point in the history
  • Loading branch information
hcodes committed Sep 4, 2017
1 parent bb02abf commit 4e68eeb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
10 changes: 5 additions & 5 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const tasks = require('./tasks');
const utils = require('./utils');
const ignore = require('./ignore');

const isTTY = process.stdin.isTTY;
const isStdin = program.stdin;
const jsonDefault = require('../.yaspellerrc.default.json');

programOptions.init({defaultIgnoreTags: jsonDefault.ignoreTags.join(',')});
Expand Down Expand Up @@ -55,14 +55,14 @@ dict.set(program.dictionary, json.dictionary);

report.addReports(program.report || json.report);

if (isTTY && !program.args.length) {
if (!isStdin && !program.args.length) {
program.help();
}

async.series(
isTTY || program.args.length ?
tasks.forResources(program.args, settings) :
tasks.forStdin(settings),
isStdin ?
tasks.forStdin(settings, program.stdinFilename) :
tasks.forResources(program.args, settings),
function() {
report.onend();
process.exit();
Expand Down
6 changes: 4 additions & 2 deletions lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ module.exports = {
params.defaultIgnoreTags +
'"', splitByCommas, null)
.option('--ignore-text <regexp>', 'ignore text using RegExp')
.option('--stdin', 'process files on <STDIN>. Default: false')
.option('--stdin-filename <file>', 'specify filename to process STDIN as')
.option('--max-requests <number>', 'max count of requests at a time. Default: 2', parseInt, 0)
.option('--only-errors', 'output only errors')
.option('--debug', 'debug mode')
.option('--check-yo', 'checking the letter Ё (Yo) in words.');
.option('--check-yo', 'checking the letter Ё (Yo) in words.')
.option('--debug', 'debug mode');

this.apiOptions.forEach(function(el) {
program.option('--' + utils.kebabCase(el[0]), el[1]);
Expand Down
5 changes: 3 additions & 2 deletions lib/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ module.exports = {
* Prepare task for stdin.
*
* @param {Object} settings
* @param {String} [filename]
* @return {Array}
*/
forStdin(settings) {
forStdin(settings, filename) {
return [function(callback) {
let text = '';

Expand All @@ -102,7 +103,7 @@ module.exports = {
onResource(
err,
err ? data : {
resource: 'stdin',
resource: filename || 'stdin',
data: data,
time: Date.now() - startTime
},
Expand Down

0 comments on commit 4e68eeb

Please sign in to comment.