CLI #10
CLI #10
Conversation
thanks @Colelyman! In addition to my comments, I would also suggest switching usage of |
#!/usr/bin/env node | ||
var fs = require('fs') | ||
var minimist = require('minimist') | ||
var fastq = require('./index') |
thejmazz
Aug 19, 2017
Member
include .js
extension
include .js
extension
thejmazz
Aug 19, 2017
Member
style: blank line after #!/usr/bin/env node
style: blank line after #!/usr/bin/env node
Colelyman
Aug 19, 2017
Author
Member
👍 these are fixed, thanks for pointing them out!
}) | ||
|
||
fq.on('error', function (err) { | ||
console.log( |
thejmazz
Aug 19, 2017
Member
one line console.log('There was an error:\n', err)
@bmpvieira @tiagofilipe12 do we have an issue for standardized error messages across modules?
one line console.log('There was an error:\n', err)
@bmpvieira @tiagofilipe12 do we have an issue for standardized error messages across modules?
Colelyman
Aug 19, 2017
Author
Member
👍 fixed
|
||
process.stdin.setEncoding('utf8') | ||
|
||
fq.on('data', function (data) { |
thejmazz
Aug 19, 2017
•
Member
using .on('data')
puts a stream into streams 1 mode - it is preferred to use a pipe instead. It would look something like
const through = require('through2')
fq.pipe(through.obj(function (data, enc, next) {
this.push(JSON.stringify(data) + '\n')
next()
// alternatively, next(null, JSON.stringify(data) + '\n')
})
.pipe(writeStream)
There is also ndjson.stringify which I believe does the same thing. (and it handles linux vs windows EOL)
So: use ndjson
module.
using .on('data')
puts a stream into streams 1 mode - it is preferred to use a pipe instead. It would look something like
const through = require('through2')
fq.pipe(through.obj(function (data, enc, next) {
this.push(JSON.stringify(data) + '\n')
next()
// alternatively, next(null, JSON.stringify(data) + '\n')
})
.pipe(writeStream)
There is also ndjson.stringify which I believe does the same thing. (and it handles linux vs windows EOL)
So: use ndjson
module.
Colelyman
Aug 19, 2017
•
Author
Member
@thejmazz I am very new to nodejs streams, so I probably just don't understand the concept behind pipes. But, would using the code that you referenced above require the parser to be refactored? From what I understand, fastq.read(argv._[0])
returns an events.EventEmitter()
object, so can an events.EventEmitter()
be piped?
Perhaps this is the function of the ndjson
module and I just don't know it.
@thejmazz I am very new to nodejs streams, so I probably just don't understand the concept behind pipes. But, would using the code that you referenced above require the parser to be refactored? From what I understand, fastq.read(argv._[0])
returns an events.EventEmitter()
object, so can an events.EventEmitter()
be piped?
Perhaps this is the function of the ndjson
module and I just don't know it.
tiagofilipe12
Aug 20, 2017
•
Member
thejmazz
Aug 21, 2017
Member
Ahh yes @Colelyman my bad - I thought this module was a stream. It does not make sense to pipe an event emitter. The CLI from this PR looks like it will work with the changes in refactoring branch - I suggest we merge this in now, finish refactoring (which I think is just some cleaning up and making sure tests pass), and as part of that can implement fs.createReadStream(input).pipe(fastq)
in the CLI - which is what it looks like @tiagofilipe12 was using to test refactoring branch.
Ahh yes @Colelyman my bad - I thought this module was a stream. It does not make sense to pipe an event emitter. The CLI from this PR looks like it will work with the changes in refactoring branch - I suggest we merge this in now, finish refactoring (which I think is just some cleaning up and making sure tests pass), and as part of that can implement fs.createReadStream(input).pipe(fastq)
in the CLI - which is what it looks like @tiagofilipe12 was using to test refactoring branch.
tiagofilipe12
Aug 21, 2017
Member
👍
Thanks @Colelyman for the contribution! |
Awesome, thanks @bmpvieira! |
This is a CLI that is heavily based on the CLI from bionode-fasta.
This PR is in response to #8.
I'm not sure if test cases are necessary for a CLI, but I can make them if needed.