diff --git a/CHANGES.md b/CHANGES.md index faee1da8..8b05e3db 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## v1.9.1 + +* Fix formatting issue on `hcloud volume list` and `hcloud volume describe` + ## v1.9.0 * Add support for volumes diff --git a/cli/server_describe.go b/cli/server_describe.go index 926c7708..73d9a063 100644 --- a/cli/server_describe.go +++ b/cli/server_describe.go @@ -66,19 +66,19 @@ func runServerDescribe(cli *CLI, cmd *cobra.Command, args []string) error { } else { fmt.Printf(" No Floating IPs\n") } - fmt.Printf(" Volumes:\n") + fmt.Printf("Volumes:\n") if len(server.Volumes) > 0 { for _, v := range server.Volumes { volume, _, err := cli.client.Volume.GetByID(cli.Context, v.ID) if err != nil { return fmt.Errorf("error fetching Volume: %v", err) } - fmt.Printf(" - ID:\t\t\t%d\n", volume.ID) - fmt.Printf(" Name:\t\t%s\n", volume.Name) - fmt.Printf(" Size:\t\t%d GB\n", volume.Size) + fmt.Printf(" - ID:\t\t%d\n", volume.ID) + fmt.Printf(" Name:\t%s\n", volume.Name) + fmt.Printf(" Size:\t%s\n", humanize.Bytes(uint64(volume.Size*humanize.GByte))) } } else { - fmt.Printf(" No Volumes\n") + fmt.Printf(" No Volumes\n") } fmt.Printf("Image:\n") if server.Image != nil { diff --git a/cli/volume_describe.go b/cli/volume_describe.go index 2ee7e970..332d2107 100644 --- a/cli/volume_describe.go +++ b/cli/volume_describe.go @@ -2,6 +2,8 @@ package cli import ( "fmt" + + "github.com/dustin/go-humanize" "github.com/spf13/cobra" ) @@ -29,26 +31,26 @@ func runVolumeDescribe(cli *CLI, cmd *cobra.Command, args []string) error { fmt.Printf("ID:\t\t%d\n", volume.ID) fmt.Printf("Name:\t\t%s\n", volume.Name) - fmt.Printf("Size:\t\t%d GB\n", volume.Size) - fmt.Printf("Linux Device:\t\t%s\n", volume.LinuxDevice) + fmt.Printf("Size:\t\t%s\n", humanize.Bytes(uint64(volume.Size*humanize.GByte))) + fmt.Printf("Linux Device:\t%s\n", volume.LinuxDevice) fmt.Printf("Location:\n") fmt.Printf(" Name:\t\t%s\n", volume.Location.Name) fmt.Printf(" Description:\t%s\n", volume.Location.Description) - fmt.Printf(" Country:\t\t%s\n", volume.Location.Country) + fmt.Printf(" Country:\t%s\n", volume.Location.Country) fmt.Printf(" City:\t\t%s\n", volume.Location.City) - fmt.Printf(" Latitude:\t\t%f\n", volume.Location.Latitude) - fmt.Printf(" Longitude:\t\t%f\n", volume.Location.Longitude) + fmt.Printf(" Latitude:\t%f\n", volume.Location.Latitude) + fmt.Printf(" Longitude:\t%f\n", volume.Location.Longitude) if volume.Server != nil { server, _, err := cli.Client().Server.GetByID(cli.Context, volume.Server.ID) if err != nil { return err } if server == nil { - return fmt.Errorf("server not found: %d", *volume.Server) + return fmt.Errorf("server not found: %d", volume.Server.ID) } fmt.Printf("Server:\n") - fmt.Printf(" ID:\t%d\n", server.ID) - fmt.Printf(" Name:\t%s\n", server.Name) + fmt.Printf(" ID:\t\t%d\n", server.ID) + fmt.Printf(" Name:\t\t%s\n", server.Name) } else { fmt.Print("Server:\n Not attached\n") } diff --git a/cli/volume_list.go b/cli/volume_list.go index 434d2273..ed618b92 100644 --- a/cli/volume_list.go +++ b/cli/volume_list.go @@ -3,6 +3,7 @@ package cli import ( "strconv" + "github.com/dustin/go-humanize" "github.com/hetznercloud/hcloud-go/hcloud" "github.com/spf13/cobra" ) @@ -20,6 +21,10 @@ func init() { } return na(server) })). + AddFieldOutputFn("size", fieldOutputFn(func(obj interface{}) string { + volume := obj.(*hcloud.Volume) + return humanize.Bytes(uint64(volume.Size * humanize.GByte)) + })). AddFieldOutputFn("location", fieldOutputFn(func(obj interface{}) string { volume := obj.(*hcloud.Volume) return volume.Location.Name