-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API CLI output formatting that is unix-idiomatic and machine-friendly #4348
Comments
Above thinking led me to a human-unfriendly format, but @ghubstan pointed out that some of us will want to use the API interactively (as in calling it from a terminal emulator, see [0] for term definition). That leads to a bit more compllicated output logic where you can choose between either a human-optimized or a machine-optimized output. The simplest solution I see is to have the machine-optimized output as outlined above, but have an optional post-processing step (in terms of implementation) that would make the output more terse, merging multiple simple columns into one complex column, and thus more human friendly. So you'd have something close to this for a human The "optional post-processing step" part is important, because it's the fact that the human friendly version is a derivative of the simple, machine-friendly version that makes the implementation simple (no duplicated logic). Another alternative to keep in mindAnother option is to use a headerless table format, which is common amongst unix tools (like
Supporting both a headered table and a headerless table would be simple enough, but we'll only investigate adopting it if the headered table format described earlier is not human friendly enough. "What would be more unix-idiomatic?"Unix has prominent tools that use headered and headerless tables.
[0] https://unix.stackexchange.com/questions/43385/what-do-you-mean-by-interactive-shell |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
One way to cover both is with an optional parameter like Outputs could then be human-readable by default for the interactive shell, but could be made machine-readable with just one flag. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically closed because of inactivity. Feel free to reopen it if you think it is still relevant. |
The new gRPC API CLI client will be outputting various types of data and we want the output format, just like the rest of the CLI client, to be unix-idiomatic. By unix-idomatic, I mean following the unix philosophy, which, most notably, includes interoperating well with other unix standard tools. The idea is for the output logic to be simple and to be able to achieve complex use cases by piping to other simple and standard tools.
Table format
Currently, the output of
getoffers
call looks more or less like this (below output is a bit dated; some things like the datetime format has changed, but currently I don't have access to my dev workspace, so using this):Above output is not easy to destructure automatically. For example, using spaces to distinguish columns is not possible:
Outputs a garbled table:
The motivation behind current formatting is human friendliness, but, after giving it more thought, true developer friendliness requires easy programmatic output interpretation.
We can use a simpler columnar format with explicit delimiters (only whitespace between columns has been changed):
To format into a human friendly table:
Output:
This requires the data to not include the delimiter, which might seem fiddly, but can be solved by allowing the user to specify a custom delimiter (e.g.
|||||
). Unless data in question might contain malicious input, sanitization shouldn't be necessary.Column complexity
Another concern is that some columns are difficult to machine parse, because they're optimized for space efficiency and general human readability.
For example, the column titled
BTC(min - max)
can either contain the offer quantity or the offer quantity range, which means it can contain two different types of data: a hyphen-deliminated tuple of floats (0.03250000 - 0.06250000
) or a single float (0.03250000
).The column
BTC(min - max)
can be unpacked into two columnsminimum BTC quantity
andmaximum BTC quantity
. That way we have the same information, but the complexity is reduced (both columns are just floats). When the quantity is a range, the new columns will have different values; otherwise, they will be the same. Same goes forUTC(min -max)
.More data in rows
There's some information, like the offer pair (e.g. BTC and USD), that's embedded in the header, but not in the data rows. That makes it impossible to mix multiple currency pairs in the same table. If pair information was in the rows, you could query
getoffers
for multiple pairs at once, or greatly simplify subscribing to push updates (one subscription for any number of pairs); in short, a table that stores all information in the rows is easier to work with.Instead of
Price in USD for 1 BTC|BTC(min - max)|USD(min - max)
, we could have:Price|Base currency|Base currency quantity(min - max)|Quote currency|Quote currency quantity(min - max)
or with the above proposed change
Price|Base currency|Minimum base currency quantity|Maximum base currency quantity|Quote currency|Minimum quote currency quantity|Maximum quote currency quantity
Some notes:
Price in USD for 1 BTC
implies it is the value of base currency being quoted against the quote currency, so I shortened it toPrice
;The text was updated successfully, but these errors were encountered: