Skip to content

Commit

Permalink
Fix volume formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
LKaemmerling authored and thcyron committed Oct 16, 2018
1 parent 3f00787 commit a7935e5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 5 additions & 5 deletions cli/server_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 10 additions & 8 deletions cli/volume_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package cli

import (
"fmt"

"github.com/dustin/go-humanize"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -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")
}
Expand Down
5 changes: 5 additions & 0 deletions cli/volume_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"strconv"

"github.com/dustin/go-humanize"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/spf13/cobra"
)
Expand All @@ -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
Expand Down

0 comments on commit a7935e5

Please sign in to comment.