base

package
v1.51.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmd

type Cmd struct {
	BaseCobraCommand func(hcapi2.Client) *cobra.Command
	Run              func(state.State, *cobra.Command, []string) error
}

Cmd allows defining commands for generic resource-based commands

func (*Cmd) CobraCommand

func (gc *Cmd) CobraCommand(s state.State) *cobra.Command

CobraCommand creates a command that can be registered with cobra.

type CreateCmd added in v1.40.0

type CreateCmd struct {
	BaseCobraCommand func(hcapi2.Client) *cobra.Command
	// Run is the function that will be called when the command is executed.
	// It should return the created resource, the schema of the resource and an error.
	Run           func(state.State, *cobra.Command, []string) (any, any, error)
	PrintResource func(state.State, *cobra.Command, any)
}

CreateCmd allows defining commands for resource creation

func (*CreateCmd) CobraCommand added in v1.40.0

func (cc *CreateCmd) CobraCommand(s state.State) *cobra.Command

CobraCommand creates a command that can be registered with cobra.

type DeleteCmd added in v1.25.0

type DeleteCmd struct {
	ResourceNameSingular string // e.g. "Server"
	ResourceNamePlural   string // e.g. "Servers"
	ShortDescription     string
	NameSuggestions      func(client hcapi2.Client) func() []string
	AdditionalFlags      func(*cobra.Command)
	Fetch                func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error)
	Delete               func(s state.State, cmd *cobra.Command, resource interface{}) (*hcloud.Action, error)
}

DeleteCmd allows defining commands for deleting a resource.

func (*DeleteCmd) CobraCommand added in v1.25.0

func (dc *DeleteCmd) CobraCommand(s state.State) *cobra.Command

CobraCommand creates a command that can be registered with cobra.

func (*DeleteCmd) Run added in v1.25.0

func (dc *DeleteCmd) Run(s state.State, cmd *cobra.Command, args []string) error

Run executes a delete command.

type DescribeCmd

type DescribeCmd[T any] struct {
	ResourceNameSingular string // e.g. "Server"
	ShortDescription     string
	NameSuggestions      func(client hcapi2.Client) func() []string
	AdditionalFlags      func(*cobra.Command)
	// Fetch is called to fetch the resource to describe.
	// The first returned interface is the resource itself as a hcloud struct, the second is the schema for the resource.
	Fetch     func(s state.State, cmd *cobra.Command, idOrName string) (T, any, error)
	PrintText func(s state.State, cmd *cobra.Command, resource T) error
}

DescribeCmd allows defining commands for describing a resource.

func (*DescribeCmd[T]) CobraCommand

func (dc *DescribeCmd[T]) CobraCommand(s state.State) *cobra.Command

CobraCommand creates a command that can be registered with cobra.

func (*DescribeCmd[T]) Run

func (dc *DescribeCmd[T]) Run(s state.State, cmd *cobra.Command, args []string) error

Run executes a describe command.

type LabelCmds

type LabelCmds[T any] struct {
	ResourceNameSingular   string
	ShortDescriptionAdd    string
	ShortDescriptionRemove string
	NameSuggestions        func(client hcapi2.Client) func() []string
	LabelKeySuggestions    func(client hcapi2.Client) func(idOrName string) []string
	Fetch                  func(s state.State, idOrName string) (T, error)
	SetLabels              func(s state.State, resource T, labels map[string]string) error
	GetLabels              func(resource T) map[string]string
	GetIDOrName            func(resource T) string
}

LabelCmds allows defining commands for adding labels to resources.

func (*LabelCmds[T]) AddCobraCommand

func (lc *LabelCmds[T]) AddCobraCommand(s state.State) *cobra.Command

AddCobraCommand creates a command that can be registered with cobra.

func (*LabelCmds[T]) RemoveCobraCommand

func (lc *LabelCmds[T]) RemoveCobraCommand(s state.State) *cobra.Command

RemoveCobraCommand creates a command that can be registered with cobra.

func (*LabelCmds[T]) RunAdd

func (lc *LabelCmds[T]) RunAdd(s state.State, cmd *cobra.Command, args []string) error

RunAdd executes an add label command

func (*LabelCmds[T]) RunRemove

func (lc *LabelCmds[T]) RunRemove(s state.State, cmd *cobra.Command, args []string) error

RunRemove executes a remove label command

type ListCmd

type ListCmd struct {
	SortOption         *config.Option[[]string]
	ResourceNamePlural string // e.g. "Servers"
	JSONKeyGetByName   string // e.g. "Servers"
	DefaultColumns     []string
	Fetch              func(state.State, *pflag.FlagSet, hcloud.ListOpts, []string) ([]interface{}, error)
	AdditionalFlags    func(*cobra.Command)
	OutputTable        func(t *output.Table, client hcapi2.Client)
	Schema             func([]interface{}) interface{}
}

ListCmd allows defining commands for listing resources

func (*ListCmd) CobraCommand

func (lc *ListCmd) CobraCommand(s state.State) *cobra.Command

CobraCommand creates a command that can be registered with cobra.

func (*ListCmd) Run

func (lc *ListCmd) Run(s state.State, cmd *cobra.Command) error

Run executes a list command

type SetRdnsCmd added in v1.28.1

type SetRdnsCmd struct {
	ResourceNameSingular string // e.g. "Server"
	ShortDescription     string
	NameSuggestions      func(client hcapi2.Client) func() []string
	Fetch                func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error)
	GetDefaultIP         func(resource interface{}) net.IP
}

SetRdnsCmd allows defining commands for setting the RDNS of a resource.

func (*SetRdnsCmd) CobraCommand added in v1.28.1

func (rc *SetRdnsCmd) CobraCommand(s state.State) *cobra.Command

CobraCommand creates a command that can be registered with cobra.

func (*SetRdnsCmd) Run added in v1.28.1

func (rc *SetRdnsCmd) Run(s state.State, cmd *cobra.Command, args []string) error

Run executes a setRDNS command.

type UpdateCmd added in v1.25.0

type UpdateCmd struct {
	ResourceNameSingular string // e.g. "Server"
	ShortDescription     string
	NameSuggestions      func(client hcapi2.Client) func() []string
	DefineFlags          func(*cobra.Command)
	Fetch                func(s state.State, cmd *cobra.Command, idOrName string) (interface{}, *hcloud.Response, error)
	Update               func(s state.State, cmd *cobra.Command, resource interface{}, flags map[string]pflag.Value) error
}

UpdateCmd allows defining commands for updating a resource.

func (*UpdateCmd) CobraCommand added in v1.25.0

func (uc *UpdateCmd) CobraCommand(s state.State) *cobra.Command

CobraCommand creates a command that can be registered with cobra.

func (*UpdateCmd) Run added in v1.25.0

func (uc *UpdateCmd) Run(s state.State, cmd *cobra.Command, args []string) error

Run executes a update command.

Jump to

Keyboard shortcuts

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