Skip to content

Commit a7935e5

Browse files
LKaemmerlingthcyron
authored andcommitted
Fix volume formatting issues
1 parent 3f00787 commit a7935e5

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changes
22

3+
## v1.9.1
4+
5+
* Fix formatting issue on `hcloud volume list` and `hcloud volume describe`
6+
37
## v1.9.0
48

59
* Add support for volumes

cli/server_describe.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,19 @@ func runServerDescribe(cli *CLI, cmd *cobra.Command, args []string) error {
6666
} else {
6767
fmt.Printf(" No Floating IPs\n")
6868
}
69-
fmt.Printf(" Volumes:\n")
69+
fmt.Printf("Volumes:\n")
7070
if len(server.Volumes) > 0 {
7171
for _, v := range server.Volumes {
7272
volume, _, err := cli.client.Volume.GetByID(cli.Context, v.ID)
7373
if err != nil {
7474
return fmt.Errorf("error fetching Volume: %v", err)
7575
}
76-
fmt.Printf(" - ID:\t\t\t%d\n", volume.ID)
77-
fmt.Printf(" Name:\t\t%s\n", volume.Name)
78-
fmt.Printf(" Size:\t\t%d GB\n", volume.Size)
76+
fmt.Printf(" - ID:\t\t%d\n", volume.ID)
77+
fmt.Printf(" Name:\t%s\n", volume.Name)
78+
fmt.Printf(" Size:\t%s\n", humanize.Bytes(uint64(volume.Size*humanize.GByte)))
7979
}
8080
} else {
81-
fmt.Printf(" No Volumes\n")
81+
fmt.Printf(" No Volumes\n")
8282
}
8383
fmt.Printf("Image:\n")
8484
if server.Image != nil {

cli/volume_describe.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package cli
22

33
import (
44
"fmt"
5+
6+
"github.com/dustin/go-humanize"
57
"github.com/spf13/cobra"
68
)
79

@@ -29,26 +31,26 @@ func runVolumeDescribe(cli *CLI, cmd *cobra.Command, args []string) error {
2931

3032
fmt.Printf("ID:\t\t%d\n", volume.ID)
3133
fmt.Printf("Name:\t\t%s\n", volume.Name)
32-
fmt.Printf("Size:\t\t%d GB\n", volume.Size)
33-
fmt.Printf("Linux Device:\t\t%s\n", volume.LinuxDevice)
34+
fmt.Printf("Size:\t\t%s\n", humanize.Bytes(uint64(volume.Size*humanize.GByte)))
35+
fmt.Printf("Linux Device:\t%s\n", volume.LinuxDevice)
3436
fmt.Printf("Location:\n")
3537
fmt.Printf(" Name:\t\t%s\n", volume.Location.Name)
3638
fmt.Printf(" Description:\t%s\n", volume.Location.Description)
37-
fmt.Printf(" Country:\t\t%s\n", volume.Location.Country)
39+
fmt.Printf(" Country:\t%s\n", volume.Location.Country)
3840
fmt.Printf(" City:\t\t%s\n", volume.Location.City)
39-
fmt.Printf(" Latitude:\t\t%f\n", volume.Location.Latitude)
40-
fmt.Printf(" Longitude:\t\t%f\n", volume.Location.Longitude)
41+
fmt.Printf(" Latitude:\t%f\n", volume.Location.Latitude)
42+
fmt.Printf(" Longitude:\t%f\n", volume.Location.Longitude)
4143
if volume.Server != nil {
4244
server, _, err := cli.Client().Server.GetByID(cli.Context, volume.Server.ID)
4345
if err != nil {
4446
return err
4547
}
4648
if server == nil {
47-
return fmt.Errorf("server not found: %d", *volume.Server)
49+
return fmt.Errorf("server not found: %d", volume.Server.ID)
4850
}
4951
fmt.Printf("Server:\n")
50-
fmt.Printf(" ID:\t%d\n", server.ID)
51-
fmt.Printf(" Name:\t%s\n", server.Name)
52+
fmt.Printf(" ID:\t\t%d\n", server.ID)
53+
fmt.Printf(" Name:\t\t%s\n", server.Name)
5254
} else {
5355
fmt.Print("Server:\n Not attached\n")
5456
}

cli/volume_list.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cli
33
import (
44
"strconv"
55

6+
"github.com/dustin/go-humanize"
67
"github.com/hetznercloud/hcloud-go/hcloud"
78
"github.com/spf13/cobra"
89
)
@@ -20,6 +21,10 @@ func init() {
2021
}
2122
return na(server)
2223
})).
24+
AddFieldOutputFn("size", fieldOutputFn(func(obj interface{}) string {
25+
volume := obj.(*hcloud.Volume)
26+
return humanize.Bytes(uint64(volume.Size * humanize.GByte))
27+
})).
2328
AddFieldOutputFn("location", fieldOutputFn(func(obj interface{}) string {
2429
volume := obj.(*hcloud.Volume)
2530
return volume.Location.Name

0 commit comments

Comments
 (0)