Documentation
¶
Index ¶
- Constants
- func ExperimentalWrapper(product, url string) func(state.State, *cobra.Command) *cobra.Command
- type Cmd
- type CreateCmd
- type DeleteCmd
- type DescribeCmd
- type FetchFunc
- type LabelCmds
- func (lc *LabelCmds[T]) AddCobraCommand(s state.State) *cobra.Command
- func (lc *LabelCmds[T]) RemoveCobraCommand(s state.State) *cobra.Command
- func (lc *LabelCmds[T]) RunAdd(s state.State, cmd *cobra.Command, args []string) error
- func (lc *LabelCmds[T]) RunRemove(s state.State, cmd *cobra.Command, args []string) error
- type ListCmd
- func (lc *ListCmd[T, S]) CobraCommand(s state.State) *cobra.Command
- func (lc *ListCmd[T, S]) FetchAny(s state.State, fs *pflag.FlagSet, opts hcloud.ListOpts, sorts []string) ([]any, error)
- func (lc *ListCmd[T, S]) GetDefaultColumns() []string
- func (lc *ListCmd[T, S]) GetJSONKeyGetByName() string
- func (lc *ListCmd[T, S]) GetResourceNamePlural() string
- func (lc *ListCmd[T, S]) Run(s state.State, cmd *cobra.Command, args []string) error
- func (lc *ListCmd[T, S]) SchemaAny(resource any) any
- func (lc *ListCmd[T, S]) UseOutputTable(t *output.Table, client hcapi2.Client)
- type Listable
- type SetRdnsCmd
- type UpdateCmd
Constants ¶
const ExperimentalStderrWarning = "" /* 126-byte string literal not displayed */
Variables ¶
This section is empty.
Functions ¶
func ExperimentalWrapper ¶ added in v1.52.0
ExperimentalWrapper create a command wrapper that appends a notice to the command descriptions and logs a warning when it is used.
Usage:
var (
ExperimentalProduct = ExperimentalWrapper("Product name", "https://docs.hetzner.cloud/changelog#new-product")
)
func (c) CobraCommand(s state.State) *cobra.Command {
cmd := &cobra.Command{
Use: "command",
Short: "My experimental command",
Long: "This is an experimental command.",
PreRunE: s.EnsureToken,
}
cmd.Run = func(cmd *cobra.Command, _ []string) {}
return ExperimentalProduct(s, cmd)
}
Types ¶
type Cmd ¶
type Cmd struct {
BaseCobraCommand func(hcapi2.Client) *cobra.Command
Run func(state.State, *cobra.Command, []string) error
// Experimental is a function that will be used to mark the command as experimental.
Experimental func(state.State, *cobra.Command) *cobra.Command
}
Cmd allows defining commands for generic resource-based commands
type CreateCmd ¶ added in v1.40.0
type CreateCmd[T any] 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) (T, any, error) PrintResource func(state.State, *cobra.Command, T) // Experimental is a function that will be used to mark the command as experimental. Experimental func(state.State, *cobra.Command) *cobra.Command }
CreateCmd allows defining commands for resource creation
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 FetchFunc
Delete func(s state.State, cmd *cobra.Command, resource interface{}) (*hcloud.Action, error)
// FetchFunc is a factory function that produces [DeleteCmd.Fetch]. Should be set in case the resource has
// more than a single identifier that is used in the positional arguments.
// See [DeleteCmd.PositionalArgumentOverride].
FetchFunc func(s state.State, cmd *cobra.Command, args []string) (FetchFunc, error)
// In case the resource does not have a single identifier that matches [DeleteCmd.ResourceNameSingular], this field
// can be set to define the list of positional arguments.
// For example, passing:
// []string{"a", "b", "c"}
// Would result in the usage string:
// <a> <b> <c>...
// Where c is are resources to be deleted.
PositionalArgumentOverride []string
// Can be set if the default [DeleteCmd.NameSuggestions] is not enough. This is usually the case when
// [DeleteCmd.FetchWithArgs] and [DeleteCmd.PositionalArgumentOverride] is being used.
ValidArgsFunction func(client hcapi2.Client) []cobra.CompletionFunc
// Experimental is a function that will be used to mark the command as experimental.
Experimental func(state.State, *cobra.Command) *cobra.Command
}
DeleteCmd allows defining commands for deleting a resource.
func (*DeleteCmd) CobraCommand ¶ added in v1.25.0
CobraCommand creates a command that can be registered with cobra.
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) // Can be set in case the resource has more than a single identifier that is used in the positional arguments. // See [DescribeCmd.PositionalArgumentOverride]. FetchWithArgs func(s state.State, cmd *cobra.Command, args []string) (T, any, error) PrintText func(s state.State, cmd *cobra.Command, resource T) error GetIDOrName func(resource T) string // In case the resource does not have a single identifier that matches [DescribeCmd.ResourceNameSingular], this field // can be set to define the list of positional arguments. // For example, passing: // []string{"a", "b", "c"} // Would result in the usage string: // <a> <b> <c> PositionalArgumentOverride []string // Can be set if the default [DescribeCmd.NameSuggestions] is not enough. This is usually the case when // [DescribeCmd.FetchWithArgs] and [DescribeCmd.PositionalArgumentOverride] is being used. ValidArgsFunction func(client hcapi2.Client) []cobra.CompletionFunc // Experimental is a function that will be used to mark the command as experimental. Experimental func(state.State, *cobra.Command) *cobra.Command }
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.
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) // Can be set in case the resource has more than a single identifier that is used in the positional arguments. // See [LabelCmds.PositionalArgumentOverride]. FetchWithArgs func(s state.State, args []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 // In case the resource does not have a single identifier that matches [LabelCmds.ResourceNameSingular], this field // can be set to define the list of positional arguments. // For example, passing: // []string{"a", "b", "c"} // Would result in the usage string: // <a> <b> <c> PositionalArgumentOverride []string // Can be set if the default [LabelCmds.NameSuggestions] is not enough. This is usually the case when // [LabelCmds.FetchWithArgs] and [LabelCmds.PositionalArgumentOverride] is being used. // // If this is being set [LabelCmds.LabelKeySuggestions] is ignored and its functionality must be // provided as part of the [LabelCmds.ValidArgsFunction]. ValidArgsFunction func(client hcapi2.Client) []cobra.CompletionFunc // Experimental is a function that will be used to mark the command as experimental. Experimental func(state.State, *cobra.Command) *cobra.Command }
LabelCmds allows defining commands for adding labels to resources.
func (*LabelCmds[T]) AddCobraCommand ¶
AddCobraCommand creates a command that can be registered with cobra.
func (*LabelCmds[T]) RemoveCobraCommand ¶
RemoveCobraCommand creates a command that can be registered with cobra.
type ListCmd ¶
type ListCmd[T any, S any] 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) ([]T, error) // Can be set in case the resource has more than a single identifier that is used in the positional arguments. // See [ListCmd.PositionalArgumentOverride]. FetchWithArgs func(s state.State, flags *pflag.FlagSet, listOpts hcloud.ListOpts, sorts []string, args []string) ([]T, error) AdditionalFlags func(*cobra.Command) OutputTable func(t *output.Table, client hcapi2.Client) Schema func(T) S // In case the resource does not have a single identifier that matches [ListCmd.ResourceNamePlural], this field // can be set to define the list of positional arguments. // For example, passing: // []string{"a", "b", "c"} // Would result in the usage string: // <a> <b> <c> PositionalArgumentOverride []string // Can be set if auto-completion is needed (usually if [ListCmd.FetchWithArgs] is used) ValidArgsFunction func(client hcapi2.Client) cobra.CompletionFunc // Experimental is a function that will be used to mark the command as experimental. Experimental func(state.State, *cobra.Command) *cobra.Command }
ListCmd allows defining commands for listing resources T is the type of the resource that is listed, e.g. *hcloud.Server S is the type of the schema that is returned, e.g. schema.Server
func (*ListCmd[T, S]) CobraCommand ¶
CobraCommand creates a command that can be registered with cobra.
func (*ListCmd[T, S]) GetDefaultColumns ¶ added in v1.52.0
func (*ListCmd[T, S]) GetJSONKeyGetByName ¶ added in v1.52.0
func (*ListCmd[T, S]) GetResourceNamePlural ¶ added in v1.52.0
type Listable ¶ added in v1.52.0
type Listable interface {
GetResourceNamePlural() string
GetJSONKeyGetByName() string
GetDefaultColumns() []string
UseOutputTable(*output.Table, hcapi2.Client)
FetchAny(state.State, *pflag.FlagSet, hcloud.ListOpts, []string) ([]any, error)
SchemaAny(any) any
}
Listable is an interface that defines the methods required for a resource to be listed. It is needed because ListCmd is a generic type, and we don't always know the concrete type of the resource. See [all.ListCmd]
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
// Experimental is a function that will be used to mark the command as experimental.
Experimental func(state.State, *cobra.Command) *cobra.Command
}
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.
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)
// Can be set in case the resource has more than a single identifier that is used in the positional arguments.
// See [UpdateCmd.PositionalArgumentOverride].
FetchWithArgs func(s state.State, cmd *cobra.Command, args []string) (any, *hcloud.Response, error)
Update func(s state.State, cmd *cobra.Command, resource interface{}, flags map[string]pflag.Value) error
// In case the resource does not have a single identifier that matches [UpdateCmd.ResourceNameSingular], this field
// can be set to define the list of positional arguments.
// For example, passing:
// []string{"a", "b", "c"}
// Would result in the usage string:
// <a> <b> <c>
PositionalArgumentOverride []string
// Can be set if the default [UpdateCmd.NameSuggestions] is not enough. This is usually the case when
// [UpdateCmd.FetchWithArgs] and [UpdateCmd.PositionalArgumentOverride] is being used.
ValidArgsFunction func(client hcapi2.Client) []cobra.CompletionFunc
// Experimental is a function that will be used to mark the command as experimental.
Experimental func(state.State, *cobra.Command) *cobra.Command
}
UpdateCmd allows defining commands for updating a resource.
func (*UpdateCmd) CobraCommand ¶ added in v1.25.0
CobraCommand creates a command that can be registered with cobra.