Skip to content

Commit fb35768

Browse files
committed
fix visual representation of list and describe
1 parent 96e5568 commit fb35768

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

internal/cmd/volume/snapshot/describe/describe.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"strings"
78

89
"github.com/goccy/go-yaml"
910
"github.com/spf13/cobra"
@@ -122,18 +123,29 @@ func outputResult(p *print.Printer, outputFormat string, snapshot *iaas.Snapshot
122123

123124
default:
124125
table := tables.NewTable()
125-
table.SetHeader("ID", "NAME", "SIZE", "STATUS", "VOLUME ID", "LABELS", "CREATED AT", "UPDATED AT")
126-
127-
table.AddRow(
128-
utils.PtrString(snapshot.Id),
129-
utils.PtrString(snapshot.Name),
130-
utils.PtrByteSizeDefault((*int64)(snapshot.Size), ""),
131-
utils.PtrString(snapshot.Status),
132-
utils.PtrString(snapshot.VolumeId),
133-
utils.PtrStringDefault(snapshot.Labels, ""),
134-
utils.ConvertTimePToDateTimeString(snapshot.CreatedAt),
135-
utils.ConvertTimePToDateTimeString(snapshot.UpdatedAt),
136-
)
126+
table.AddRow("ID", utils.PtrString(snapshot.Id))
127+
table.AddSeparator()
128+
table.AddRow("NAME", utils.PtrString(snapshot.Name))
129+
table.AddSeparator()
130+
table.AddRow("SIZE", utils.PtrByteSizeDefault((*int64)(snapshot.Size), ""))
131+
table.AddSeparator()
132+
table.AddRow("STATUS", utils.PtrString(snapshot.Status))
133+
table.AddSeparator()
134+
table.AddRow("VOLUME ID", utils.PtrString(snapshot.VolumeId))
135+
table.AddSeparator()
136+
137+
if snapshot.Labels != nil && len(*snapshot.Labels) > 0 {
138+
labels := []string{}
139+
for key, value := range *snapshot.Labels {
140+
labels = append(labels, fmt.Sprintf("%s: %s", key, value))
141+
}
142+
table.AddRow("LABELS", strings.Join(labels, "\n"))
143+
table.AddSeparator()
144+
}
145+
146+
table.AddRow("CREATED AT", utils.ConvertTimePToDateTimeString(snapshot.CreatedAt))
147+
table.AddSeparator()
148+
table.AddRow("UPDATED AT", utils.ConvertTimePToDateTimeString(snapshot.UpdatedAt))
137149

138150
err := table.Display(p)
139151
if err != nil {

internal/cmd/volume/snapshot/list/list.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,10 @@ func outputResult(p *print.Printer, outputFormat string, snapshots []iaas.Snapsh
177177
utils.ConvertTimePToDateTimeString(snapshot.CreatedAt),
178178
utils.ConvertTimePToDateTimeString(snapshot.UpdatedAt),
179179
)
180-
}
181-
err := table.Display(p)
182-
if err != nil {
183-
return fmt.Errorf("render table: %w", err)
180+
table.AddSeparator()
184181
}
185182

183+
p.Outputln(table.Render())
186184
return nil
187185
}
188186
}

0 commit comments

Comments
 (0)