Skip to content

Commit

Permalink
Fix streaming: add --stdin flag
Browse files Browse the repository at this point in the history
Closes GH-189.
  • Loading branch information
wooorm committed Aug 25, 2018
1 parent d2fde31 commit 7ae54e2
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cli.js
Expand Up @@ -51,19 +51,21 @@ var cli = meow(
' -q, --quiet output only warnings and errors',
' -t, --text treat input as plain-text (not markdown)',
' -d, --diff ignore unchanged lines (affects Travis only)',
' --stdin read from stdin',
'',
'When no input files are given, searches for markdown and text',
'files in the current directory, `doc`, and `docs`.',
'',
'Examples',
' $ echo "His network looks good" | alex',
' $ echo "His network looks good" | alex --stdin',
' $ alex *.md !example.md',
' $ alex'
].join('\n'),
{
flags: {
version: {type: 'boolean', alias: 'v'},
help: {type: 'boolean', alias: 'h'},
stdin: {type: 'boolean'},
text: {type: 'boolean', alias: 't'},
diff: {type: 'boolean', alias: 'd'},
quiet: {type: 'boolean', alias: 'q'},
Expand All @@ -73,10 +75,16 @@ var cli = meow(
)

/* Set-up. */
var globs = ['{docs/**/,doc/**/,}*.{' + extensions.join(',') + '}']
var defaultGlobs = ['{docs/**/,doc/**/,}*.{' + extensions.join(',') + '}']
var globs

/* istanbul ignore else - Bug in tests. Something hangs, at least. */
if (cli.input.length !== 0) {
if (cli.flags.stdin) {
if (cli.input.length !== 0) {
throw new Error('Do not pass globs with `--stdin`')
}
} else if (cli.input.length === 0) {
globs = defaultGlobs
} else {
globs = cli.input
}

Expand Down
47 changes: 47 additions & 0 deletions test/cli.js
Expand Up @@ -25,6 +25,33 @@ test('help', function(t) {
})
})

test('stdin', function(t) {
return execa
.stderr('./cli.js', ['--stdin'], {input: 'His'})
.catch(function(err) {
t.is(
err.stderr,
[
'<stdin>',
' 1:1-1:4 warning `His` may be insensitive, use `Their`, `Theirs`, `Them` instead her-him retext-equality',
'',
'⚠ 1 warning',
''
].join('\n')
)
})
})

test('stdin and globs', function(t) {
var rp = path.join('test', 'fixtures', 'one.md')

return execa
.stderr('./cli.js', ['--stdin', rp], {input: 'His'})
.catch(function(err) {
t.regex(err.stderr, /Do not pass globs with `--stdin`/)
})
})

test('markdown by default', function(t) {
var rp = path.join('test', 'fixtures', 'one.md')

Expand Down Expand Up @@ -107,3 +134,23 @@ test('non-binary (optional)', function(t) {
t.is(err.stderr, expected)
})
})

test('default globs', function(t) {
return execa.stderr('./cli.js').catch(function(err) {
var expected = [
'code-of-conduct.md',
' 1:1 error Cannot process specified file: it’s ignored',
'',
'contributing.md: no issues found',
'example.md',
' 1:1 error Cannot process specified file: it’s ignored',
'',
'readme.md: no issues found',
'',
'✖ 2 errors',
''
].join('\n')

t.is(err.stderr, expected)
})
})

0 comments on commit 7ae54e2

Please sign in to comment.