digitalocean / doctl

The official command line interface for the DigitalOcean API.
https://docs.digitalocean.com/reference/doctl/
Apache License 2.0
3.26k stars 398 forks source link

Add CSV export alongisde text/json #1365

Open Justinzobel opened 1 year ago

Justinzobel commented 1 year ago

What is the problem this feature would solve? Please describe. I'm always frustrated when I want to work with the data exported from doctl and I can't output it in a basic CSV output that is easy to parse in many scripts.

Describe the solution you'd like CSV output

Additional context None

Justinzobel commented 10 months ago

Any chance of this?

MrCuPper commented 10 months ago

Chance of what? Can you let me know a bit more about your point ?

On Mon, Jan 8, 2024, 05:00 Justin @.***> wrote:

Any chance of this?

— Reply to this email directly, view it on GitHub https://github.com/digitalocean/doctl/issues/1365#issuecomment-1880274477, or unsubscribe https://github.com/notifications/unsubscribe-auth/BCZN2V27IN52EPZF75LJMQLYNND4ZAVCNFSM6AAAAAAXAUCAFCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOBQGI3TINBXG4 . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Justinzobel commented 10 months ago

The point is to have CSV as an output option, that is all. Any chance of it being implemented is the question.

MrCuPper commented 10 months ago

The code is not written by me but you can ask @danaelhe , she solved the problem, i guess, honestly stranger with codes here

On Mon, Jan 8, 2024, 06:18 Justin @.***> wrote:

The point is to have CSV as an output option, that is all. Any chance of it being implemented is the question.

— Reply to this email directly, view it on GitHub https://github.com/digitalocean/doctl/issues/1365#issuecomment-1880316831, or unsubscribe https://github.com/notifications/unsubscribe-auth/BCZN2VZXXCAYSSEIJEJXPALYNNM7PAVCNFSM6AAAAAAXAUCAFCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOBQGMYTMOBTGE . You are receiving this because you commented.Message ID: @.***>

danaelhe commented 10 months ago

Hi there and thank you for bubbling this back up!

I've used third party tools such as json2csv to accomplish this. Something like: doctl compute ssh-key ls -o json | json2csv will output a csv that I was able to cleanly import into an excel sheet. Would that work for you?

Justinzobel commented 10 months ago

I haven't tried json2csv but if that can be integrated into doctl that would be great. I'm trying to get a list of snapshots via compute snapshot list --no-header --format=ID,Name,CreatedAt,ResourceType,Size so I can see which ones I need to clean up, etc.

danaelhe commented 9 months ago

Oh yes, I was able to do that with json2csv like this:

doctl compute snapshot list --no-header --format=ID,Name,CreatedAt,ResourceType,Size -o json | json2csv
"id","name","resource_type","regions","min_disk_size","size_gigabytes","created_at"
"811111113","ubuntu-18.04-minimal","droplet","[""nyc3""]",15,0.17,"2021-04-16T17:05:33Z"

This wouldn't be a straightforward feature to integrate in doctl as that logic is baked into the Go CLI package we use, Cobra. Since there are numerous options of cli tools that can convert the outputted JSON into a CSV, we consider that a viable workaround in the meantime.