Skip to content

Commit

Permalink
Add colors to some missing UUIDs (#74)
Browse files Browse the repository at this point in the history
* fix(colors): add missing uuid colors

Signed-off-by: Amine Kherbouche <[email protected]>

* fix(network): prevent displaying empty servers list

Signed-off-by: Amine Kherbouche <[email protected]>
  • Loading branch information
kaminek authored Apr 27, 2021
1 parent 80f8e76 commit 259ed2d
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 58 deletions.
6 changes: 5 additions & 1 deletion internal/commands/ipaddress/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ func (s *showCommand) Execute(exec commands.Executor, arg string) (output.Output
{Title: "Family:", Key: "access", Value: ipAddress.Family},
{Title: "Part of Plan:", Key: "access", Value: ipAddress.PartOfPlan, Format: output.BoolFormat},
{Title: "PTR Record:", Key: "access", Value: ipAddress.PTRRecord},
{Title: "Server UUID:", Key: "access", Value: ipAddress.ServerUUID},
{
Title: "Server UUID:",
Key: "access", Value: ipAddress.ServerUUID,
Color: ui.DefaultUUUIDColours,
},
{Title: "MAC:", Key: "credits", Value: ipAddress.MAC},
{Title: "Floating:", Key: "credits", Value: ipAddress.Floating, Format: output.BoolFormat},
{Title: "Zone:", Key: "zone", Value: ipAddress.Zone},
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/network/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (s *listCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Ou
Columns: []output.TableColumn{
{Key: "uuid", Header: "UUID", Color: ui.DefaultUUUIDColours},
{Key: "name", Header: "Name"},
{Key: "router", Header: "Router"},
{Key: "router", Header: "Router", Color: ui.DefaultUUUIDColours},
{Key: "type", Header: "Type"},
{Key: "zone", Header: "Zone"},
},
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/network/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func createTable(networks []upcloud.Network) output.Table {
Columns: []output.TableColumn{
{Header: "UUID", Key: "uuid", Hidden: false, Color: ui.DefaultUUUIDColours},
{Header: "Name", Key: "name", Hidden: false},
{Header: "Router", Key: "router", Hidden: false},
{Header: "Router", Key: "router", Hidden: false, Color: ui.DefaultUUUIDColours},
{Header: "Type", Key: "type", Hidden: false},
{Header: "Zone", Key: "zone", Hidden: false},
},
Expand Down
112 changes: 60 additions & 52 deletions internal/commands/network/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,30 @@ func (s *showCommand) Execute(exec commands.Executor, arg string) (output.Output
if err != nil {
return nil, err
}
commonSection := output.CombinedSection{Key: "", Title: "", Contents: output.Details{
Sections: []output.DetailSection{
{
Title: "Common",
Rows: []output.DetailRow{
{Title: "UUID:", Key: "uuid", Value: network.UUID, Color: ui.DefaultUUUIDColours},
{Title: "Name:", Key: "name", Value: network.Name},
{Title: "Router:", Key: "router", Value: network.Router},
{Title: "Type:", Key: "type", Value: network.Type},
{Title: "Zone:", Key: "zone", Value: network.Zone},

combined := output.Combined{
output.CombinedSection{
Key: "",
Title: "",
Contents: output.Details{
Sections: []output.DetailSection{
{
Title: "Common",
Rows: []output.DetailRow{
{Title: "UUID:", Key: "uuid", Value: network.UUID, Color: ui.DefaultUUUIDColours},
{Title: "Name:", Key: "name", Value: network.Name},
{Title: "Router:", Key: "router", Value: network.Router},
{Title: "Type:", Key: "type", Value: network.Type},
{Title: "Zone:", Key: "zone", Value: network.Zone},
},
},
},
},
},
},
}

networkRows := make([]output.TableRow, 0)
if len(network.IPNetworks) > 0 {
networkRows := make([]output.TableRow, 0)
for _, nip := range network.IPNetworks {
networkRows = append(networkRows, output.TableRow{
nip.Address,
Expand All @@ -67,50 +73,52 @@ func (s *showCommand) Execute(exec commands.Executor, arg string) (output.Output
strings.Join(nip.DHCPDns, " "),
})
}
}
networkSection := output.CombinedSection{
Key: "ip_networks",
Title: "IP Networks:",
Contents: output.Table{
Columns: []output.TableColumn{
{Key: "address", Header: "Address", Color: ui.DefaultAddressColours},
{Key: "family", Header: "Family"},
{Key: "dhcp", Header: "DHCP", Format: output.BoolFormat},
{Key: "dhcp_default_route", Header: "DHCP Def Router", Format: output.BoolFormat},
{Key: "dhcp_dns", Header: "DHCP DNS"},

combined = append(combined, output.CombinedSection{
Key: "ip_networks",
Title: "IP Networks:",
Contents: output.Table{
Columns: []output.TableColumn{
{Key: "address", Header: "Address", Color: ui.DefaultAddressColours},
{Key: "family", Header: "Family"},
{Key: "dhcp", Header: "DHCP", Format: output.BoolFormat},
{Key: "dhcp_default_route", Header: "DHCP Def Router", Format: output.BoolFormat},
{Key: "dhcp_dns", Header: "DHCP DNS"},
},
Rows: networkRows,
},
Rows: networkRows,
}}
})
}

serverRows := make([]output.TableRow, 0)
for _, server := range network.Servers {
fetched, err := exec.Server().GetServerDetails(&request.GetServerDetailsRequest{UUID: server.ServerUUID})
if err != nil {
return nil, fmt.Errorf("error getting server %v details: %w", server.ServerUUID, err)
if len(network.Servers) > 0 {
serverRows := make([]output.TableRow, 0)
for _, server := range network.Servers {
fetched, err := exec.Server().GetServerDetails(&request.GetServerDetailsRequest{UUID: server.ServerUUID})
if err != nil {
return nil, fmt.Errorf("error getting server %v details: %w", server.ServerUUID, err)
}
serverRows = append(serverRows, output.TableRow{
fetched.UUID,
fetched.Title,
fetched.Hostname,
fetched.State,
})
}
serverRows = append(serverRows, output.TableRow{
fetched.UUID,
fetched.Title,
fetched.Hostname,
fetched.State,

combined = append(combined, output.CombinedSection{
Key: "servers",
Title: "Servers:",
Contents: output.Table{
Columns: []output.TableColumn{
{Header: "UUID", Key: "uuid", Color: ui.DefaultUUUIDColours},
{Header: "Title", Key: "title"},
{Header: "Hostname", Key: "hostname"},
{Header: "State", Key: "state"},
},
Rows: serverRows,
},
})
}
serverSection := output.CombinedSection{
Key: "servers",
Title: "Servers:",
Contents: output.Table{
Columns: []output.TableColumn{
{Header: "UUID", Key: "uuid", Color: ui.DefaultUUUIDColours},
{Header: "Title", Key: "title"},
{Header: "Hostname", Key: "hostname"},
{Header: "State", Key: "state"},
},
Rows: serverRows,
}}

return output.Combined{
commonSection,
networkSection,
serverSection,
}, nil
return combined, nil
}
3 changes: 2 additions & 1 deletion internal/commands/server/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/UpCloudLtd/upcloud-cli/internal/commands"
"github.com/UpCloudLtd/upcloud-cli/internal/output"
"github.com/UpCloudLtd/upcloud-cli/internal/ui"
)

// ListCommand creates the "server list" command
Expand Down Expand Up @@ -44,7 +45,7 @@ func (s *listCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Ou

return output.Table{
Columns: []output.TableColumn{
{Key: "uuid", Header: "UUID"},
{Key: "uuid", Header: "UUID", Color: ui.DefaultUUUIDColours},
{Key: "hostname", Header: "Hostname"},
{Key: "plan", Header: "Plan"},
{Key: "zone", Header: "Zone"},
Expand Down
4 changes: 2 additions & 2 deletions internal/commands/server/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (s *showCommand) Execute(exec commands.Executor, uuid string) (output.Outpu
{
Title: "Common",
Rows: []output.DetailRow{
{Title: "UUID:", Key: "uuid", Value: server.UUID},
{Title: "UUID:", Key: "uuid", Value: server.UUID, Color: ui.DefaultUUUIDColours},
{Title: "Hostname:", Key: "hostname", Value: server.Hostname},
{Title: "Title:", Key: "title", Value: server.Title},
{Title: "Plan:", Key: "plan", Value: planOutput},
Expand Down Expand Up @@ -177,7 +177,7 @@ func (s *showCommand) Execute(exec commands.Executor, uuid string) (output.Outpu
{Key: "type", Header: "Type"},
{Key: "ip_address", Header: "IP Address"},
{Key: "mac_address", Header: "MAC Address"},
{Key: "network", Header: "Network"},
{Key: "network", Header: "Network", Color: ui.DefaultUUUIDColours},
{Key: "flags", Header: "Flags"},
},
Rows: nicRows,
Expand Down

0 comments on commit 259ed2d

Please sign in to comment.