Skip to content

Commit 164cb09

Browse files
committed
build: allow reading from stdin
1 parent c6c36b9 commit 164cb09

File tree

1 file changed

+23
-1
lines changed
  • lib/node_modules/@stdlib/_tools/links/validate/bin

1 file changed

+23
-1
lines changed

lib/node_modules/@stdlib/_tools/links/validate/bin/cli

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
var join = require( 'path' ).join;
2626
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
2727
var CLI = require( '@stdlib/cli/ctor' );
28+
var stdin = require( '@stdlib/process/read-stdin' );
29+
var stdinStream = require( '@stdlib/streams/node/stdin' );
2830
var validateLinks = require( './../lib' );
2931

3032

@@ -64,8 +66,28 @@ function main() {
6466
if ( flags.database ) {
6567
opts.database = flags.database;
6668
}
69+
// Check if we are receiving data from `stdin`...
70+
if ( !stdinStream.isTTY ) {
71+
return stdin( onRead );
72+
}
6773
return validateLinks( JSON.parse( args[ 0 ] ), opts, done );
6874

75+
/**
76+
* Callback invoked upon reading from `stdin`.
77+
*
78+
* @private
79+
* @param {(Error|null)} error - error object
80+
* @param {Buffer} data - data
81+
* @returns {void}
82+
*/
83+
function onRead( error, data ) {
84+
if ( error ) {
85+
return cli.error( error );
86+
}
87+
data = data.toString()
88+
validateLinks( JSON.parse( data ), opts, done );
89+
}
90+
6991
/**
7092
* Callback invoked upon completion.
7193
*
@@ -80,7 +102,7 @@ function main() {
80102
return cli.error( error );
81103
}
82104
if ( validationErrors.length > 0 ) {
83-
console.log( validationErrors );
105+
console.log( JSON.stringify( validationErrors ) );
84106
} else {
85107
console.log( 'All links are valid.' );
86108
}

0 commit comments

Comments
 (0)