civo / cli

Our Command Line Interface (CLI) for interacting with your Civo resources
Apache License 2.0
173 stars 86 forks source link

`civo <resourcetype> ls` should show output even if empty #231

Open kaihoffman opened 2 years ago

kaihoffman commented 2 years ago

Currently, if you have selected a region where you have no resources, you may get an empty response to a listing of resources:

$ civo instance ls
$

This is confusing especially if you do not know you have changed regions.

It might be helpful to have a note about which region you're in when listing a region with an empty output. Compare to output from a listing with instances running in it, which shows the region:

$ civo instance ls
+--------------------------------------+--------------+--------+----------+-----------+------+----------+---------------+-------------+--------+
| ID                                   | Hostname     | Region | Size     | Cpu Cores | Ram  | SSD disk | Public IP     | Private IP  | Status |
+--------------------------------------+--------------+--------+----------+-----------+------+----------+---------------+-------------+--------+
| aa068118-40ac-4fc8-b5ea-fb5202a2061a |   hostname   | LON1   | g3.small |         1 | 2048 |       25 | 12.34.56.78 | 192.168.1.2 | ACTIVE |
+--------------------------------------+--------------+--------+----------+-----------+------+----------+---------------+-------------+--------+

I suggest having something like

$ civo instance ls
Current region is NYC1. No instances found.
kitarp29 commented 2 years ago

Hi @kaihoffman @andyjeffries @DMajrekar I would love to work on this. Could you assign this issue to me?

kaihoffman commented 2 years ago

@kitarp29 did you have a chance to look at this? Would love to be able to close this off!

kitarp29 commented 2 years ago

Hi @kaihoffman Sorry for the delay got stuck with University exams. Could you direct me to right file or location I will find the output to the commands?

kaihoffman commented 2 years ago

It would need to determine whether the resourcetype is found, and determine the output accordingly @kitarp29 .

For example, the instance ls command output is at https://github.com/civo/cli/blob/master/cmd/instance/instance_list.go but it would need to apply equally to other resource types that can be listed.

kitarp29 commented 2 years ago

If the fix I applied here works for you, I will replicate for the other commands as well :)

kitarp29 commented 2 years ago

Hey @kaihoffman Could have a look into this It's not a big breaking change, if you could conform we can get this done sooner.

kaihoffman commented 2 years ago

@kitarp29 I'm not the best placed to judge a golang PR in our team, I'm afraid - I'll leave it to @alejandrojnm or @RealHarshThakur to have a look?

kitarp29 commented 2 years ago

I mean I'm very new to the codebase myself, so can't say I have the best approach. But surely an approach that will work :)

kaihoffman commented 2 years ago

It's less about the particular codebase and more about best practices @kitarp29 - I'm not qualified to judge what is efficient and idiomatic golang.