Skip to content
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

Machine friendly output #297

Closed
tomjn opened this issue Nov 4, 2022 · 8 comments · Fixed by #394
Closed

Machine friendly output #297

tomjn opened this issue Nov 4, 2022 · 8 comments · Fixed by #394
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@tomjn
Copy link

tomjn commented Nov 4, 2022

Tarts CLI commands output human friendly text, but for automation and integrations it's better to print in a machine readable format such as JSON or XML.

To this end the addition of a general --json parameter for all CLI commands would be a great help

@fkorotkov
Copy link
Contributor

Do you have particular commands that need machine readable output? There are couple of services that already integrated Tart as is since the outputs are already pretty simple. For example, tart ip just returns a single like so it's possible to do things like ssh admin@$(tart ip ventura-base).

@josephburnett
Copy link

+1

This commit c9caeab#diff-6279a63c53e5ce2ed8800fb80676147b5c5976824b5bc982640295a32eb3a683R51 broke our (GitLab) parsing of tart list because it added a space before each tab. We are fixing it by being a little more robust with our parsing: https://gitlab.com/gitlab-org/fleeting/nesting/-/merge_requests/4 but it still isn't 100% correct.

A JSON output format would really help here.

@fkorotkov
Copy link
Contributor

Sorry to hear that @josephburnett! It seems overtime there was a need for JSON output only for list command. ip and get already return machine readable output.

It seems this issue can be addressed by a tart list --json which will output for each local or remote VM a line with a JSON object that contains all available information like name, settings, size, etc.

@tomjn
Copy link
Author

tomjn commented Jan 17, 2023

@fkorotkov is that in an upcoming release? tart list --json doesn't work in the current release and there's no --json parameter in the help text

@josephburnett
Copy link

No big deal. If tart was written in golang I would send you a pull request instead of an issue ;)

A more standard way to implement tart list --json would be to emit a single JSON list with objects for each VM. Most JSON readers expect a single value rather than line separated values. Not very Unix-like, but it's easiest from a tooling perspective.

@fkorotkov
Copy link
Contributor

@tomjn tart list --json is a proposal for a change after which we can close this issue.

@josephburnett with a single value it can even be pretty printed for human eyes. 🤔

@tomjn
Copy link
Author

tomjn commented Jan 17, 2023

@fkorotkov ok but if it is implemented, the entire response should be a single JSON response

for example this:

[
    { ... },
    { ... }
]

Not this:

{ ... }
{ ... }

Doing that immediately eliminates CLI commands such as jq, or piping, and forces everybody to write custom code to reprocess and normalise the output before it can be used.

Ideally, Tart internally would return data that can then be printed either as JSON or XML or human readable text, rather than printing it directly as it figures it out.

vms = getvms( filteroptions )
if output is json
    print json encoded ( vms )
else
    foreach vm
       print vm line etc

This also makes unit tests possible

@tomjn
Copy link
Author

tomjn commented Jan 17, 2023

I'd also suggest an --format parameter so --format="json" for future proofing

fkorotkov added a commit that referenced this issue Feb 2, 2023
In the light of the upcoming `1.0.0` release and stabilizing of the API, let's introduce some breaking changes for the good.

Removed all the `--cpu`, `--memory`, `--disk` and `--display` flags and replaced with a single `--json` flag for machine-readable output.

Added `--json` option to the `list` command to output a single JSON list. Notably removed `--quite` flag since it seemed unnecessary.

Fixes #297
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants