Skip to content

Pretty-print JSON in api command output#1114

Merged
vilmibm merged 7 commits intotrunkfrom
pretty-json
Jun 10, 2020
Merged

Pretty-print JSON in api command output#1114
vilmibm merged 7 commits intotrunkfrom
pretty-json

Conversation

@mislav
Copy link
Contributor

@mislav mislav commented Jun 5, 2020

Before:

{"data":{"viewer":{"login":"mislav","following":{"totalCount":22},"isSiteAdmin":true}}}

After:
Screen Shot 2020-06-05 at 5 44 42 PM

This should make it easier on the eyes when playing around with GitHub API. When the output is piped to a script, the data returned from the server is as before (unprocessed).

Ref. #332

@mislav mislav requested review from probablycorey and vilmibm June 5, 2020 15:46
mislav added 5 commits June 5, 2020 18:24
Most API errors are present in the response body itself, which will be
sent to stdout normally, but if stdout is redirected somewhere (as it's
common with scripts), failed HTTP requests will likely sabotage the rest
of the script, but no useful info will be shown on stderr.

This makes it so all REST and GraphQL errors are always shown on stderr.
Additionally, this makes sure that the command exits with a nonzero
status on any GraphQL errors.
Print HTTP errors on stderr in `api` command
Copy link
Contributor

@probablycorey probablycorey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the output so much easier to parse and use. Looks great!

Copy link
Contributor

@vilmibm vilmibm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My instinct is to be nervous about a custom json parser + raw ansi codes but the code is intelligible and it works 👍

@vilmibm vilmibm merged commit 446486f into trunk Jun 10, 2020
@mislav mislav deleted the pretty-json branch June 11, 2020 09:05
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.

3 participants