node-gh / gh

(DEPRECATED) GitHub CLI made with NodeJS. Use the official https://cli.github.com/ instead.
http://nodegh.io
Other
1.71k stars 217 forks source link

Question: How to get output of gh in json (or csv, or some scriptable format) ? #447

Closed taherv closed 8 years ago

taherv commented 8 years ago

I'd like to use gh in a script to parse pull requests .... how do I get it to ouput in json or csv or some other machine parseable format ?

henvic commented 8 years ago

Hi @taherv, I'm sorry but it only outputs human-readable text (which is parseable - just not automagically, anyways). However, even though on the first releases gh didn't follow the Unix philosophy (see below) it mostly does it now and we intend it to always do it.

So you can (kind of) trust we are never going to change the behavior or feedback type without very good reason (say, making them more Unix-like).

So you are good to go identifying patterns and relying on them. Just make sure you don't use it for critical stuff.

tl;dr: 1) exit code != 0 => error; exit code == 0 => identify patterns and parse accordingly.

This is the Unix philosophy: Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface. ~ Doug McIlroy, inventor of the Unix pipe.

Related: https://github.com/node-gh/gh/issues/357

taherv commented 8 years ago

Thanks @henvic I agree with the principle of doing one thing, and doing it well. Although I have my own interpretation of whether output format is a separate capability or not. For example ls, a classic example, does output differently based on certain "conditions" .....

When you want to follow this philosophy, you probably want to output in a format that is the lowest common denominator of all. So that other people can build on it.

For e.g., here, if you take my advice the output will be not-colored, and machine-parseable (which is very very basic). Human readable output can be built on top of that outside the tool .....

I will close this bug as "Won't change anything !". As far as I am concerned, you have answered my quesiton. Thanks a lot !