File: describe.go

package info (click to toggle)
hcloud-cli 1.39.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,628 kB
  • sloc: sh: 36; makefile: 7
file content (47 lines) | stat: -rw-r--r-- 1,818 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package servertype

import (
	"context"
	"fmt"

	"github.com/spf13/cobra"

	"github.com/hetznercloud/cli/internal/cmd/base"
	"github.com/hetznercloud/cli/internal/cmd/util"
	"github.com/hetznercloud/cli/internal/hcapi2"
	"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

var describeCmd = base.DescribeCmd{
	ResourceNameSingular: "serverType",
	ShortDescription:     "Describe a server type",
	JSONKeyGetByID:       "server_type",
	JSONKeyGetByName:     "server_types",
	NameSuggestions:      func(c hcapi2.Client) func() []string { return c.ServerType().Names },
	Fetch: func(ctx context.Context, client hcapi2.Client, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) {
		return client.ServerType().Get(ctx, idOrName)
	},
	PrintText: func(_ context.Context, _ hcapi2.Client, _ *cobra.Command, resource interface{}) error {
		serverType := resource.(*hcloud.ServerType)

		fmt.Printf("ID:\t\t\t%d\n", serverType.ID)
		fmt.Printf("Name:\t\t\t%s\n", serverType.Name)
		fmt.Printf("Description:\t\t%s\n", serverType.Description)
		fmt.Printf("Cores:\t\t\t%d\n", serverType.Cores)
		fmt.Printf("CPU Type:\t\t%s\n", serverType.CPUType)
		fmt.Printf("Architecture:\t\t%s\n", serverType.Architecture)
		fmt.Printf("Memory:\t\t\t%.1f GB\n", serverType.Memory)
		fmt.Printf("Disk:\t\t\t%d GB\n", serverType.Disk)
		fmt.Printf("Storage Type:\t\t%s\n", serverType.StorageType)
		fmt.Printf("Included Traffic:\t%d TB\n", serverType.IncludedTraffic/util.Tebibyte)
		fmt.Printf(util.DescribeDeprecation(serverType))

		fmt.Printf("Pricings per Location:\n")
		for _, price := range serverType.Pricings {
			fmt.Printf("  - Location:\t%s:\n", price.Location.Name)
			fmt.Printf("    Hourly:\t€ %s\n", price.Hourly.Gross)
			fmt.Printf("    Monthly:\t€ %s\n", price.Monthly.Gross)
		}
		return nil
	},
}