Skip to content

Commit 3551dc4

Browse files
committed
feat(database): color state in database list output
1 parent 5c0eadf commit 3551dc4

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

internal/commands/database/list.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ func (s *listCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Ou
2828

2929
rows := []output.TableRow{}
3030
for _, db := range databases {
31+
coloredState := commands.DatabaseStateColour(db.State).Sprint(db.State)
32+
3133
rows = append(rows, output.TableRow{
3234
db.UUID,
3335
db.Title,
3436
db.Type,
3537
db.Plan,
3638
db.Zone,
37-
db.State,
39+
coloredState,
3840
})
3941
}
4042

internal/commands/util.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ func SearchResources(
7272
return result, nil
7373
}
7474

75+
// DatabaseStateColour maps database states to colours
76+
func DatabaseStateColour(state upcloud.ManagedDatabaseState) text.Colors {
77+
switch state {
78+
case upcloud.ManagedDatabaseStateRunning:
79+
return text.Colors{text.FgGreen}
80+
case "rebuilding", "rebalancing":
81+
return text.Colors{text.FgYellow}
82+
default:
83+
return text.Colors{text.FgHiBlack}
84+
}
85+
}
86+
7587
// ServerStateColour is a helper mapping server states to colours
7688
func ServerStateColour(state string) text.Colors {
7789
switch state {

0 commit comments

Comments
 (0)