location

package
v1.39.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DescribeCmd = base.DescribeCmd{
	ResourceNameSingular: "location",
	ShortDescription:     "Describe a location",
	JSONKeyGetByID:       "location",
	JSONKeyGetByName:     "locations",
	NameSuggestions:      func(c hcapi2.Client) func() []string { return c.Location().Names },
	Fetch: func(ctx context.Context, client hcapi2.Client, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error) {
		return client.Location().Get(ctx, idOrName)
	},
	PrintText: func(ctx context.Context, client hcapi2.Client, cmd *cobra.Command, resource interface{}) error {
		location := resource.(*hcloud.Location)

		fmt.Printf("ID:\t\t%d\n", location.ID)
		fmt.Printf("Name:\t\t%s\n", location.Name)
		fmt.Printf("Description:\t%s\n", location.Description)
		fmt.Printf("Network Zone:\t%s\n", location.NetworkZone)
		fmt.Printf("Country:\t%s\n", location.Country)
		fmt.Printf("City:\t\t%s\n", location.City)
		fmt.Printf("Latitude:\t%f\n", location.Latitude)
		fmt.Printf("Longitude:\t%f\n", location.Longitude)
		return nil
	},
}

DescribeCmd defines a command for describing a location.

View Source
var ListCmd = base.ListCmd{
	ResourceNamePlural: "locations",
	JSONKeyGetByName:   "locations",
	DefaultColumns:     []string{"id", "name", "description", "network_zone", "country", "city"},

	Fetch: func(ctx context.Context, client hcapi2.Client, _ *pflag.FlagSet, listOpts hcloud.ListOpts, sorts []string) ([]interface{}, error) {
		opts := hcloud.LocationListOpts{ListOpts: listOpts}
		if len(sorts) > 0 {
			opts.Sort = sorts
		}
		locations, _, err := client.Location().List(ctx, opts)

		var resources []interface{}
		for _, n := range locations {
			resources = append(resources, n)
		}
		return resources, err
	},

	OutputTable: func(_ hcapi2.Client) *output.Table {
		return output.NewTable().
			AddAllowedFields(hcloud.Location{})
	},

	JSONSchema: func(resources []interface{}) interface{} {
		locationSchemas := make([]schema.Location, 0, len(resources))
		for _, resource := range resources {
			location := resource.(*hcloud.Location)
			locationSchemas = append(locationSchemas, util.LocationToSchema(*location))
		}
		return locationSchemas
	},
}

Functions

func NewCommand

func NewCommand(cli *state.State, client hcapi2.Client) *cobra.Command

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL