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

fix(network): show full API response in marshaled outputs #260

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **Breaking**: In JSON and YAML output of `database list`: display the full API response. Value of `title` is not replaced with value from `name`, if `title` is empty.
- **Breaking**: In JSON and YAML output of `database types`: display the full API response. This changes the top level datatype from list to object, where keys are the available database type, e.g., `pg` and `mysql`.
- **Breaking**: In JSON and YAML output of `ip-address list`: display full API response. This changes `partofplan` key to `part_of_plan` and `ptrrecord` key to `ptr_record`.
- **Breaking**: In JSON and YAML output of `network list` and `network show`: display full API response. Servers list will only contain server UUID and name. `ip_networks` contains subfield `ip_network` which in turn contains the networks.
- In human readable output of `kubernetes show` command, show node-groups as table. Node-group details are available with `kubernetes nodegroup show` command.

## Fixed
Expand Down
20 changes: 12 additions & 8 deletions internal/commands/network/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,18 @@ func (s *listCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Ou
n.Zone,
})
}
return output.Table{
Columns: []output.TableColumn{
{Key: "uuid", Header: "UUID", Colour: ui.DefaultUUUIDColours},
{Key: "name", Header: "Name"},
{Key: "router", Header: "Router", Colour: ui.DefaultUUUIDColours},
{Key: "type", Header: "Type"},
{Key: "zone", Header: "Zone"},

return output.MarshaledWithHumanOutput{
Value: upcloud.Networks{Networks: filtered},
Output: output.Table{
Columns: []output.TableColumn{
{Key: "uuid", Header: "UUID", Colour: ui.DefaultUUUIDColours},
{Key: "name", Header: "Name"},
{Key: "router", Header: "Router", Colour: ui.DefaultUUUIDColours},
{Key: "type", Header: "Type"},
{Key: "zone", Header: "Zone"},
},
Rows: rows,
},
Rows: rows,
}, nil
}
25 changes: 14 additions & 11 deletions internal/commands/network/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,31 @@ func TestListCommand(t *testing.T) {
res, err := c.(commands.NoArgumentCommand).ExecuteWithoutArguments(commands.NewExecutor(cfg, &mService, flume.New("test")))

assert.Nil(t, err)
assert.Equal(t, createTable(test.expected), res)
assert.Equal(t, createOutput(test.expected), res)
})
}
}

func createTable(networks []upcloud.Network) output.Table {
func createOutput(networks []upcloud.Network) output.MarshaledWithHumanOutput {
rows := []output.TableRow{}
for _, network := range networks {
rows = append(rows,
output.TableRow{network.UUID, network.Name, network.Router, network.Type, network.Zone},
)
}

return output.Table{
HideHeader: false,
Columns: []output.TableColumn{
{Header: "UUID", Key: "uuid", Hidden: false, Colour: ui.DefaultUUUIDColours},
{Header: "Name", Key: "name", Hidden: false},
{Header: "Router", Key: "router", Hidden: false, Colour: ui.DefaultUUUIDColours},
{Header: "Type", Key: "type", Hidden: false},
{Header: "Zone", Key: "zone", Hidden: false},
return output.MarshaledWithHumanOutput{
Value: upcloud.Networks{Networks: networks},
Output: output.Table{
HideHeader: false,
Columns: []output.TableColumn{
{Header: "UUID", Key: "uuid", Hidden: false, Colour: ui.DefaultUUUIDColours},
{Header: "Name", Key: "name", Hidden: false},
{Header: "Router", Key: "router", Hidden: false, Colour: ui.DefaultUUUIDColours},
{Header: "Type", Key: "type", Hidden: false},
{Header: "Zone", Key: "zone", Hidden: false},
},
Rows: rows,
},
Rows: rows,
}
}
5 changes: 4 additions & 1 deletion internal/commands/network/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ func (s *showCommand) Execute(exec commands.Executor, arg string) (output.Output
})
}

return combined, nil
return output.MarshaledWithHumanOutput{
Value: network,
Output: combined,
}, nil
}

func formatShowDHCPDNS(val interface{}) (text.Colors, string, error) {
Expand Down