doctl icon indicating copy to clipboard operation
doctl copied to clipboard

Add CSV export alongisde text/json

Open Justinzobel opened this issue 2 years ago • 7 comments

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 avatar Apr 17 '23 04:04 Justinzobel

Any chance of this?

Justinzobel avatar Jan 08 '24 01:01 Justinzobel

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: @.***>

MrCuPper avatar Jan 08 '24 02:01 MrCuPper

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

Justinzobel avatar Jan 08 '24 02:01 Justinzobel

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: @.***>

MrCuPper avatar Jan 08 '24 02:01 MrCuPper

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?

danaelhe avatar Jan 08 '24 18:01 danaelhe

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.

Justinzobel avatar Jan 09 '24 00:01 Justinzobel

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.

danaelhe avatar Jan 17 '24 17:01 danaelhe