From 3eb94a96f20ad8a014e80e1791459bafb3216fc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20V=C3=A4lim=C3=A4ki?= <110451292+villevsv-upcloud@users.noreply.github.com> Date: Mon, 16 Oct 2023 16:46:19 +0300 Subject: [PATCH] fix(storage): show full API response in marshaled outputs after filter (#254) --- CHANGELOG.md | 1 + internal/commands/storage/list.go | 29 ++++++++++++++++------------- internal/commands/storage/show.go | 5 ++++- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4991326f1..a678607b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - **Breaking**: In JSON and YAML output of `loadbalancer list`: display full API response. This changes `state` field to `operational_state`. +- **Breaking**: `storage list` and `storage show` JSON and YAML outputs to return full API response. This changes `servers` field to contain `server` field, which in turn contains the servers. `labels` field will not be outputted if empty. - In human readable output of `kubernetes show` command, show node-groups as table. Node-group datails are available with `kubernetes nodegroup show` command. ## Removed diff --git a/internal/commands/storage/list.go b/internal/commands/storage/list.go index f311b6130..6a3f7e81d 100644 --- a/internal/commands/storage/list.go +++ b/internal/commands/storage/list.go @@ -59,7 +59,7 @@ func (s *listCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Ou } CachedStorages = storageList.Storages - var filtered []upcloud.Storage + filtered := make([]upcloud.Storage, 0) for _, v := range storageList.Storages { if s.all.Value() { filtered = append(filtered, v) @@ -109,18 +109,21 @@ func (s *listCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Ou }) } - return output.Table{ - Columns: []output.TableColumn{ - {Key: "uuid", Header: "UUID", Colour: ui.DefaultUUUIDColours}, - {Key: "title", Header: "Title"}, - {Key: "type", Header: "Type"}, - {Key: "size", Header: "Size"}, - {Key: "state", Header: "State", Format: format.StorageState}, - {Key: "tier", Header: "Tier"}, - {Key: "zone", Header: "Zone"}, - {Key: "access", Header: "Access"}, - {Key: "created", Header: "Created"}, + return output.MarshaledWithHumanOutput{ + Value: filtered, + Output: output.Table{ + Columns: []output.TableColumn{ + {Key: "uuid", Header: "UUID", Colour: ui.DefaultUUUIDColours}, + {Key: "title", Header: "Title"}, + {Key: "type", Header: "Type"}, + {Key: "size", Header: "Size"}, + {Key: "state", Header: "State", Format: format.StorageState}, + {Key: "tier", Header: "Tier"}, + {Key: "zone", Header: "Zone"}, + {Key: "access", Header: "Access"}, + {Key: "created", Header: "Created"}, + }, + Rows: rows, }, - Rows: rows, }, nil } diff --git a/internal/commands/storage/show.go b/internal/commands/storage/show.go index 2a17bd722..29e056d2b 100644 --- a/internal/commands/storage/show.go +++ b/internal/commands/storage/show.go @@ -113,7 +113,10 @@ func (s *showCommand) Execute(exec commands.Executor, uuid string) (output.Outpu }) } - return combined, nil + return output.MarshaledWithHumanOutput{ + Value: storage, + Output: combined, + }, nil } func formatShowServers(val interface{}) (text.Colors, string, error) {