jednano / gitlike-cli

A git-like CLI library for Node.js
16 stars 2 forks source link

Unexpected stdin #3

Open denis-sokolov opened 9 years ago

denis-sokolov commented 9 years ago

fed037ba9 has added an ability to automatically add stdin to the list of files accepted by the program. That's unexpected by developers who test their tools interactively, but whose tools later break when ran in a non-interactive environment. The documentation does not seem to mention this at all, making this a doubly unexpected surprise.

Moreover, the list of arguments is not necessarily a list of files, so adding stdin there might not be meaningful at all.

In case of eclint, for example, the code loops over the arguments treating them as string globs, and stdin in the list crashes the entire program.

Perhaps it would make sense to revert the default behavior and make programs that are able to handle stdin opt-in explicitly?

jednano commented 9 years ago

I was trying to enable piping in the shell. Are you saying I should expose a flag that allows one to pipe, only if the flag is provided? It seems a flag to turn off the behavior might make more sense. What do you think?

denis-sokolov commented 9 years ago

Oh, you're the author of both modules! I missed that!

I believe that users of gitlike-cli (authors of modules like eclint) need to handle stdin differently than other arguments. Whether the user calls fs.readFile or glob.replace, he needs to treat the stdin differently. If that is the case, he needs to be aware of the chance stdin is passed in. If he is aware of that, it means he's read the paragraph about it in the docs, meaning he can easily opt-in by enabling the flag.

All the users who are not aware stdin might be passed in cannot be asked to opt-in. They have seen an example where args.files is a list of strings and they happily use gitlike-cli until the day comes where their library blows up.

It's a nice idea to attempt to make stdin transparent, but unfortunately it does not work.

edi9999 commented 7 years ago

I agree with what denis-sokolov says, it is quite unexpected to have things of different types in arg.files : "strings" and "streams".

It would make more sense imo to never mix both types of parameters, but rather have 'arg.files' and 'arg.streams'

jednano commented 6 years ago

And you're saying it makes more sense to opt into the streams, right? With a --stdin flag or something of that nature?

edi9999 commented 6 years ago

Yes, somethig making explicit the use of stdin.

edi9999 commented 6 years ago

--stdin flag, why not.