Skip to content

Commit 6dbb720

Browse files
authored
fix(network): show full API response in marshaled outputs (#260)
1 parent 0b98d35 commit 6dbb720

4 files changed

Lines changed: 31 additions & 20 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2525
- **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.
2626
- **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`.
2727
- **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`.
28+
- **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.
2829
- In human readable output of `kubernetes show` command, show node-groups as table. Node-group details are available with `kubernetes nodegroup show` command.
2930

3031
## Fixed

internal/commands/network/list.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,18 @@ func (s *listCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Ou
9292
n.Zone,
9393
})
9494
}
95-
return output.Table{
96-
Columns: []output.TableColumn{
97-
{Key: "uuid", Header: "UUID", Colour: ui.DefaultUUUIDColours},
98-
{Key: "name", Header: "Name"},
99-
{Key: "router", Header: "Router", Colour: ui.DefaultUUUIDColours},
100-
{Key: "type", Header: "Type"},
101-
{Key: "zone", Header: "Zone"},
95+
96+
return output.MarshaledWithHumanOutput{
97+
Value: upcloud.Networks{Networks: filtered},
98+
Output: output.Table{
99+
Columns: []output.TableColumn{
100+
{Key: "uuid", Header: "UUID", Colour: ui.DefaultUUUIDColours},
101+
{Key: "name", Header: "Name"},
102+
{Key: "router", Header: "Router", Colour: ui.DefaultUUUIDColours},
103+
{Key: "type", Header: "Type"},
104+
{Key: "zone", Header: "Zone"},
105+
},
106+
Rows: rows,
102107
},
103-
Rows: rows,
104108
}, nil
105109
}

internal/commands/network/list_test.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,28 +87,31 @@ func TestListCommand(t *testing.T) {
8787
res, err := c.(commands.NoArgumentCommand).ExecuteWithoutArguments(commands.NewExecutor(cfg, &mService, flume.New("test")))
8888

8989
assert.Nil(t, err)
90-
assert.Equal(t, createTable(test.expected), res)
90+
assert.Equal(t, createOutput(test.expected), res)
9191
})
9292
}
9393
}
9494

95-
func createTable(networks []upcloud.Network) output.Table {
95+
func createOutput(networks []upcloud.Network) output.MarshaledWithHumanOutput {
9696
rows := []output.TableRow{}
9797
for _, network := range networks {
9898
rows = append(rows,
9999
output.TableRow{network.UUID, network.Name, network.Router, network.Type, network.Zone},
100100
)
101101
}
102102

103-
return output.Table{
104-
HideHeader: false,
105-
Columns: []output.TableColumn{
106-
{Header: "UUID", Key: "uuid", Hidden: false, Colour: ui.DefaultUUUIDColours},
107-
{Header: "Name", Key: "name", Hidden: false},
108-
{Header: "Router", Key: "router", Hidden: false, Colour: ui.DefaultUUUIDColours},
109-
{Header: "Type", Key: "type", Hidden: false},
110-
{Header: "Zone", Key: "zone", Hidden: false},
103+
return output.MarshaledWithHumanOutput{
104+
Value: upcloud.Networks{Networks: networks},
105+
Output: output.Table{
106+
HideHeader: false,
107+
Columns: []output.TableColumn{
108+
{Header: "UUID", Key: "uuid", Hidden: false, Colour: ui.DefaultUUUIDColours},
109+
{Header: "Name", Key: "name", Hidden: false},
110+
{Header: "Router", Key: "router", Hidden: false, Colour: ui.DefaultUUUIDColours},
111+
{Header: "Type", Key: "type", Hidden: false},
112+
{Header: "Zone", Key: "zone", Hidden: false},
113+
},
114+
Rows: rows,
111115
},
112-
Rows: rows,
113116
}
114117
}

internal/commands/network/show.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ func (s *showCommand) Execute(exec commands.Executor, arg string) (output.Output
128128
})
129129
}
130130

131-
return combined, nil
131+
return output.MarshaledWithHumanOutput{
132+
Value: network,
133+
Output: combined,
134+
}, nil
132135
}
133136

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

0 commit comments

Comments
 (0)