Skip to content

Implement reading input from stdin#459

Merged
jcoupey merged 1 commit intoVROOM-Project:masterfrom
krypt-n:feature/stdin
Feb 23, 2021
Merged

Implement reading input from stdin#459
jcoupey merged 1 commit intoVROOM-Project:masterfrom
krypt-n:feature/stdin

Conversation

@krypt-n
Copy link
Copy Markdown
Contributor

@krypt-n krypt-n commented Feb 21, 2021

Issue

Fixes #457

Tasks

  • Update CHANGELOG.md
  • review

Description

With these changes, vroom follows the following strategy for getting its input:

  1. If there are spare arguments, read the first spare argument as input
  2. If the -i FILE option was used, read FILE as input
  3. Otherwise read stdin as input

Previously vroom would display its help string in case 3. This degrades the experience for new users somewhat, since executing vroom without any arguments won't appear to do anything until the user closes stdin with ^D, which then results in a cryptic json parsing exception.

Alternatives to consider:

  • Only read from stdin as input if stdin is not a tty (unsure how portable isatty is)
  • Display help string if the input read from stdin has length 0 or is not valid json

@jcoupey
Copy link
Copy Markdown
Collaborator

jcoupey commented Feb 22, 2021

Thanks for submitting a PR!

Display help string if the input read from stdin has length 0 or is not valid json

In that case the error will be caught down the line upon parsing so I think we can keep things that way. It would be consistent with the current behavior, both vroom '' and vroom -i missing_file.json currently error with {"code":2,"error":"The document is empty. (offset: 0)"}.

Only read from stdin as input if stdin is not a tty

I'm not sure to get the implications here but I'm not very familiar with this kind of stuff. In what situation would this be an improvement?

@jcoupey jcoupey added this to the v1.10.0 milestone Feb 22, 2021
@krypt-n
Copy link
Copy Markdown
Contributor Author

krypt-n commented Feb 22, 2021

I'm not sure to get the implications here but I'm not very familiar with this kind of stuff. In what situation would this be an improvement?

Running vroom from a terminal without arguments would still print the help message (potentially helping new users) and running cat problem.json | vroom would work as expected. The downside is that there is no way to do this via the C++ standard library and we would have to use isatty for unix-like systems and something else for windows.

@jcoupey
Copy link
Copy Markdown
Collaborator

jcoupey commented Feb 23, 2021

I think we can live with vroom (without arguments) not displaying the help message, after all it's a case of misuse and there is an appropriate error message. Also we provide the -h flag, which is the way most command-line users would expect to get some help.

@krypt-n
Copy link
Copy Markdown
Contributor Author

krypt-n commented Feb 23, 2021

Alright, I added this change to the changelog. This is ready to merge, I think

@jcoupey jcoupey merged commit 313e1f9 into VROOM-Project:master Feb 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

read json problem from stdin

2 participants