Skip to content

Instantly share code, notes, and snippets.

@kemitchell
Created June 11, 2019 02:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kemitchell/65bc012d641da664bb920a12ca57e9f9 to your computer and use it in GitHub Desktop.
Save kemitchell/65bc012d641da664bb920a12ca57e9f9 to your computer and use it in GitHub Desktop.
#!/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