cmdutil

package
v3.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: BSD-3-Clause Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ShowAllLimit   = -1
	AllFlagUsage   = "Return every item, ignoring pagination"
	StartFlagUsage = "Offset for pagination (rounded down to a multiple of --limit on database-backed resources)"
)
View Source
const (
	ScopeRead        = "read"
	ScopeMerged      = "merged"
	ScopeAll         = "all"
	ScopeDestination = "destination"
	ScopeResource    = "resource"
	ScopeGlobal      = "global"
)
View Source
const (
	MaxPromptOptions = 20
)

Variables

This section is empty.

Functions

func AbortUploadSession

func AbortUploadSession(ctx context.Context, c *client.Client, kind, sessionID string)

func AllowPrompt

func AllowPrompt(cmd *cobra.Command) bool

func AppendQuery

func AppendQuery(path string, extra url.Values) string

func ApplyPaginationParams

func ApplyPaginationParams(cmd *cobra.Command, path string, p ListParams) (string, error)

func AssumeYes

func AssumeYes(cmd *cobra.Command) bool

func ClientFromCommand

func ClientFromCommand(cmd *cobra.Command) (*client.Client, error)

func ConfirmOrCancel

func ConfirmOrCancel(cmd *cobra.Command, opts ConfirmOptions) (bool, error)

func DecodeJSON

func DecodeJSON(resp *http.Response, out any) error

func EffectiveLimit

func EffectiveLimit(cmd *cobra.Command, resource, flagName string, flagValue, fallbackDefault int) int

func EnsureSuccessStatus

func EnsureSuccessStatus(resp *http.Response) error

func EnumVarP

func EnumVarP[T ~string](cmd *cobra.Command, flags *pflag.FlagSet, p *T, name, shorthand string, value T, usage string, allowed ...T)

The empty value is always allowed as unset; invalid nonempty defaults panic.

func ExclusiveFlags

func ExclusiveFlags(cmd *cobra.Command, names ...string) error

func JSONOutputEnabled

func JSONOutputEnabled(cmd *cobra.Command) bool

Runtime JSON mode includes --output json, even when --json is explicitly false.

func LooksLikeIDPrefix

func LooksLikeIDPrefix(identifierLower string) bool

func PrintJSON

func PrintJSON(v any) error

func PrintRawJSON

func PrintRawJSON(body []byte) error

func PrintTable

func PrintTable(cmd *cobra.Command, headers []string, rows [][]string, summaries ...TableSummary) error

func ReadJSONBody

func ReadJSONBody(resp *http.Response) ([]byte, error)

func Run

func Run[T any](cmd *cobra.Command, c *client.Client, spec Spec[T]) error

func RunDelete

func RunDelete(cmd *cobra.Command, c *client.Client, spec DeleteSpec) error

func RunEnvironments

func RunEnvironments(cmd *cobra.Command, args []string, run func(*cobra.Command, []string) error, mutation bool) error

func RunList

func RunList[T any](cmd *cobra.Command, c *client.Client, spec ListSpec[T]) error

func RunMerged

func RunMerged(cmd *cobra.Command, args []string, run func(*cobra.Command, []string) error) error

func RunScoped

func RunScoped(cmd *cobra.Command, args []string, run func(*cobra.Command, []string) error) error

func Scope

func Scope(cmd *cobra.Command) string

func SetResource

func SetResource[D, S any](ref ResourceRef[D, S], commands ...*cobra.Command)

func SetScope

func SetScope(scope string, commands ...*cobra.Command)

func UnauthClientFromCommand

func UnauthClientFromCommand(cmd *cobra.Command) (*client.Client, error)

func UploadFileInChunks

func UploadFileInChunks(ctx context.Context, c *client.Client, kind, filePath string, showProgress bool) (string, error)

Types

type ConfirmOptions

type ConfirmOptions struct {
	Label string
	Force bool
}

type DeleteSpec

type DeleteSpec struct {
	Body                                         any
	Prompt, Path, FailureMessage, SuccessMessage string
	Force                                        bool
}

type EnumValue

type EnumValue[T ~string] struct {
	// contains filtered or unexported fields
}

func (*EnumValue[T]) Set

func (v *EnumValue[T]) Set(value string) error

func (*EnumValue[T]) String

func (v *EnumValue[T]) String() string

func (*EnumValue[T]) Type

func (v *EnumValue[T]) Type() string

Type keeps enum flags compatible with pflag's GetString accessor.

type HTTPStatusError

type HTTPStatusError struct {
	Body       string
	StatusCode int
}

func (*HTTPStatusError) Error

func (e *HTTPStatusError) Error() string

type ListParams

type ListParams struct {
	Resource        string
	Limit           int
	FallbackDefault int
	Start           int
	All             bool
}

type ListSpec

type ListSpec[T any] struct {
	Query url.Values

	Row      func(T) []string
	Resource string
	Endpoint string

	Headers []string
	Params  ListParams
}

type ResourceRef

type ResourceRef[D any, S any] struct {
	GetPath          func(envID, identifier string) string
	ListPath         func(envID string) string
	SearchCandidates func(context.Context, *client.Client, string) ([]S, error)
	SelectCandidate  func([]S, string, bool) (*S, error)
	Validate         func(D, string) error
	Matches          func(item S, identifierLower, original string) bool
	Label            func(S) string
	Promote          func(S) *D

	IDOf         func(S) string
	IdentifierOf func(D) string
	Exact        func(item S, identifierLower, original string) bool
	Singular     string
	Plural       string
	IDHint       string
	ListCmd      string

	EnvironmentScoped bool
}

D is the detail shape and S is the list summary.

func (ResourceRef[D, S]) Fetch

func (ref ResourceRef[D, S]) Fetch(ctx context.Context, c *client.Client, identifier string, allowPrompt bool) (*D, error)

func (ResourceRef[D, S]) Resolve

func (ref ResourceRef[D, S]) Resolve(ctx context.Context, c *client.Client, identifier string, allowPrompt bool) (*D, bool, error)

type Spec

type Spec[T any] struct {
	Body                         any
	Render                       func(T) error
	Method, Path, FailureMessage string
	Timeout                      time.Duration
}

type TableSummary

type TableSummary struct {
	Resource  string
	Total     int64
	Paginated bool
}

Jump to

Keyboard shortcuts

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