Created
June 11, 2019 02:17
-
-
Save kemitchell/65bc012d641da664bb920a12ca57e9f9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env node | |
require('yargs') | |
.scriptName('cat') | |
.command( | |
'$0 [FILE..]', | |
'Concatenate FILE(s) to standard output.', | |
function (yargs) { | |
return yargs | |
.positional('FILE', { | |
describe: 'input file', | |
defaultDescription: 'standard input' | |
}) | |
}, | |
function (args) { | |
if (args.FILE) { | |
require('run-series')( | |
args.FILE.map(function (file) { | |
return function (done) { | |
require('fs').createReadStream(file) | |
.once('end', function () { | |
done() | |
}) | |
.pipe(process.stdout) | |
} | |
}) | |
) | |
} else { | |
process.stdin.pipe(process.stdout) | |
} | |
} | |
) | |
.help() | |
.alias('h', 'help') | |
.parse() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment