|
| 1 | +package storageboxtype |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/dustin/go-humanize" |
| 5 | + "github.com/spf13/cobra" |
| 6 | + |
| 7 | + "github.com/hetznercloud/cli/internal/cmd/base" |
| 8 | + "github.com/hetznercloud/cli/internal/cmd/util" |
| 9 | + "github.com/hetznercloud/cli/internal/hcapi2" |
| 10 | + "github.com/hetznercloud/cli/internal/state" |
| 11 | + "github.com/hetznercloud/hcloud-go/v2/hcloud" |
| 12 | +) |
| 13 | + |
| 14 | +var DescribeCmd = base.DescribeCmd[*hcloud.StorageBoxType]{ |
| 15 | + ResourceNameSingular: "Storage Box Type", |
| 16 | + ShortDescription: "Describe a Storage Box Type", |
| 17 | + NameSuggestions: func(c hcapi2.Client) func() []string { return c.StorageBoxType().Names }, |
| 18 | + Fetch: func(s state.State, _ *cobra.Command, idOrName string) (*hcloud.StorageBoxType, any, error) { |
| 19 | + st, _, err := s.Client().StorageBoxType().Get(s, idOrName) |
| 20 | + if err != nil { |
| 21 | + return nil, nil, err |
| 22 | + } |
| 23 | + return st, hcloud.SchemaFromStorageBoxType(st), nil |
| 24 | + }, |
| 25 | + PrintText: func(s state.State, cmd *cobra.Command, storageBoxType *hcloud.StorageBoxType) error { |
| 26 | + cmd.Printf("ID:\t\t\t\t%d\n", storageBoxType.ID) |
| 27 | + cmd.Printf("Name:\t\t\t\t%s\n", storageBoxType.Name) |
| 28 | + cmd.Printf("Description:\t\t\t%s\n", storageBoxType.Description) |
| 29 | + cmd.Printf("Size:\t\t\t\t%s\n", humanize.IBytes(uint64(storageBoxType.Size))) |
| 30 | + cmd.Printf("Snapshot Limit:\t\t\t%d\n", storageBoxType.SnapshotLimit) |
| 31 | + cmd.Printf("Automatic Snapshot Limit:\t%d\n", storageBoxType.AutomaticSnapshotLimit) |
| 32 | + cmd.Printf("Subaccounts Limit:\t\t%d\n", storageBoxType.SubaccountsLimit) |
| 33 | + cmd.Print(util.DescribeDeprecation(storageBoxType)) |
| 34 | + |
| 35 | + err := loadCurrencyFromAPI(s, storageBoxType) |
| 36 | + if err != nil { |
| 37 | + cmd.PrintErrf("failed to get currency for Storage Box Type prices: %v", err) |
| 38 | + } |
| 39 | + |
| 40 | + cmd.Printf("Pricings per Location:\n") |
| 41 | + for _, price := range storageBoxType.Pricings { |
| 42 | + cmd.Printf(" - Location:\t%s\n", price.Location) |
| 43 | + cmd.Printf(" Hourly:\t%s\n", util.GrossPrice(price.PriceHourly)) |
| 44 | + cmd.Printf(" Monthly:\t%s\n", util.GrossPrice(price.PriceMonthly)) |
| 45 | + cmd.Printf(" Setup Fee:\t%s\n", util.GrossPrice(price.SetupFee)) |
| 46 | + cmd.Printf("\n") |
| 47 | + } |
| 48 | + |
| 49 | + return nil |
| 50 | + }, |
| 51 | +} |
| 52 | + |
| 53 | +func loadCurrencyFromAPI(s state.State, storageBoxType *hcloud.StorageBoxType) error { |
| 54 | + pricing, _, err := s.Client().Pricing().Get(s) |
| 55 | + if err != nil { |
| 56 | + return err |
| 57 | + } |
| 58 | + |
| 59 | + for i := range storageBoxType.Pricings { |
| 60 | + storageBoxType.Pricings[i].PriceMonthly.Currency = pricing.Currency |
| 61 | + storageBoxType.Pricings[i].PriceMonthly.VATRate = pricing.VATRate |
| 62 | + |
| 63 | + storageBoxType.Pricings[i].PriceHourly.Currency = pricing.Currency |
| 64 | + storageBoxType.Pricings[i].PriceHourly.VATRate = pricing.VATRate |
| 65 | + |
| 66 | + storageBoxType.Pricings[i].SetupFee.Currency = pricing.Currency |
| 67 | + storageBoxType.Pricings[i].SetupFee.VATRate = pricing.VATRate |
| 68 | + } |
| 69 | + |
| 70 | + return nil |
| 71 | +} |
0 commit comments