cmd

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfirmDelete added in v0.3.4

func ConfirmDelete(helper Helper, description string, warnings ...string) error

ConfirmDelete prompts the user to confirm destructive delete operations unless the --force flag was provided.

func DeleteAutoApproveEnabled added in v0.3.4

func DeleteAutoApproveEnabled(helper Helper) bool

DeleteAutoApproveEnabled reports whether the user opted to skip confirmation prompts.

func DeleteForceEnabled added in v0.3.4

func DeleteForceEnabled(helper Helper) bool

DeleteForceEnabled reports whether the current helper is operating in force mode (confirmation prompts should be skipped).

func SetDeleteAutoApprove added in v0.3.4

func SetDeleteAutoApprove(cmd *cobra.Command, approved bool)

SetDeleteAutoApprove stores the --yes/--approve flag state.

func SetDeleteForce added in v0.3.4

func SetDeleteForce(cmd *cobra.Command, force bool)

SetDeleteForce stores the --force flag value on the command context so that nested delete handlers can read it without rebinding flags or configs.

func TryConvertErrorToAttrs

func TryConvertErrorToAttrs(err error) []any

Will try and json unmarshal an error string into a slice of interfaces that match the slog algorithm for varadic parameters (alternating key value pairs)

Types

type CommandHelper

type CommandHelper struct {
	// Cmd is a pointer to the command that is being executed
	Cmd *cobra.Command
	// Args are the arguments (not flags) passed to the command
	Args []string
}

func (*CommandHelper) GetArgs

func (r *CommandHelper) GetArgs() []string

func (*CommandHelper) GetBuildInfo

func (r *CommandHelper) GetBuildInfo() (*build.Info, error)

func (*CommandHelper) GetCmd

func (r *CommandHelper) GetCmd() *cobra.Command

func (*CommandHelper) GetConfig

func (r *CommandHelper) GetConfig() (config.Hook, error)

func (*CommandHelper) GetContext

func (r *CommandHelper) GetContext() context.Context

func (*CommandHelper) GetKonnectSDK added in v0.0.13

func (r *CommandHelper) GetKonnectSDK(cfg config.Hook, logger *slog.Logger) (helpers.SDKAPI, error)

func (*CommandHelper) GetLogger

func (r *CommandHelper) GetLogger() (*slog.Logger, error)

func (*CommandHelper) GetOutputFormat

func (r *CommandHelper) GetOutputFormat() (common.OutputFormat, error)

func (*CommandHelper) GetProduct

func (r *CommandHelper) GetProduct() (products.ProductValue, error)

func (*CommandHelper) GetStreams

func (r *CommandHelper) GetStreams() *iostreams.IOStreams

func (*CommandHelper) GetVerb

func (r *CommandHelper) GetVerb() (verbs.VerbValue, error)

type Common

type Common interface {
	// contains filtered or unexported methods
}

type ConfigurationError

type ConfigurationError struct {
	Err error
}

ConfigurationError represents errors that are a result of bad flags, combinations of flags, configuration settings, environment values, or other command usage issues.

func (*ConfigurationError) Error

func (e *ConfigurationError) Error() string

type ExecutionError

type ExecutionError struct {
	// friendly error message to display to the user
	Msg string
	// Err is the error that occurred during execution
	Err error
	// Optional attributes that can be used to provide additional context to the error
	Attrs []any
}

ExecutionError represents errors that occur after a command has been validated and an unsuccessful result occurs. Network errors, server side errors, invalid credentials or responses are examples of RunttimeError types.

func PrepareExecutionError

func PrepareExecutionError(msg string, err error, cmd *cobra.Command, attrs ...any) *ExecutionError

This will construct an execution error AND turn off error and usage output for the command

func PrepareExecutionErrorFromErr added in v0.3.2

func PrepareExecutionErrorFromErr(helper Helper, err error, attrs ...any) *ExecutionError

PrepareExecutionErrorFromErr converts an arbitrary error into an ExecutionError while silencing usage/error output on the associated command. The friendly message defaults to the underlying error string when msg is empty.

func PrepareExecutionErrorMsg added in v0.3.2

func PrepareExecutionErrorMsg(helper Helper, msg string, attrs ...any) *ExecutionError

PrepareExecutionErrorMsg builds an ExecutionError from a message when a backing error is not already available.

func PrepareExecutionErrorWithHelper added in v0.3.2

func PrepareExecutionErrorWithHelper(helper Helper, msg string, err error, attrs ...any) *ExecutionError

PrepareExecutionErrorWithHelper mirrors PrepareExecutionError but accepts a Helper. It ensures command usage/error output is silenced for runtime failures.

func (*ExecutionError) Error

func (e *ExecutionError) Error() string

type FlagEnum

type FlagEnum struct {
	Allowed []string
	Value   string
}

func NewEnum

func NewEnum(allowed []string, d string) *FlagEnum

func (*FlagEnum) Set

func (a *FlagEnum) Set(p string) error

func (FlagEnum) String

func (a FlagEnum) String() string

func (*FlagEnum) Type

func (a *FlagEnum) Type() string

type Helper

type Helper interface {
	GetCmd() *cobra.Command
	GetArgs() []string
	GetVerb() (verbs.VerbValue, error)
	GetProduct() (products.ProductValue, error)
	GetStreams() *iostreams.IOStreams
	GetConfig() (config.Hook, error)
	GetOutputFormat() (common.OutputFormat, error)
	GetLogger() (*slog.Logger, error)
	GetBuildInfo() (*build.Info, error)
	GetContext() context.Context
	GetKonnectSDK(cfg config.Hook, logger *slog.Logger) (helpers.SDKAPI, error)
}

func BuildHelper

func BuildHelper(cmd *cobra.Command, args []string) Helper

type MockHelper

type MockHelper struct {
	mock.Mock
}

MockHelper is an autogenerated mock type for the Helper type

func NewMockHelper

func NewMockHelper(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockHelper

NewMockHelper creates a new instance of MockHelper. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockHelper) EXPECT

func (_m *MockHelper) EXPECT() *MockHelper_Expecter

func (*MockHelper) GetArgs

func (_m *MockHelper) GetArgs() []string

GetArgs provides a mock function with no fields

func (*MockHelper) GetBuildInfo

func (_m *MockHelper) GetBuildInfo() (*build.Info, error)

GetBuildInfo provides a mock function with no fields

func (*MockHelper) GetCmd

func (_m *MockHelper) GetCmd() *cobra.Command

GetCmd provides a mock function with no fields

func (*MockHelper) GetConfig

func (_m *MockHelper) GetConfig() (config.Hook, error)

GetConfig provides a mock function with no fields

func (*MockHelper) GetContext

func (_m *MockHelper) GetContext() context.Context

GetContext provides a mock function with no fields

func (*MockHelper) GetKonnectSDK added in v0.0.13

func (_m *MockHelper) GetKonnectSDK(cfg config.Hook, logger *slog.Logger) (helpers.SDKAPI, error)

GetKonnectSDK provides a mock function with given fields: cfg, logger

func (*MockHelper) GetLogger

func (_m *MockHelper) GetLogger() (*slog.Logger, error)

GetLogger provides a mock function with no fields

func (*MockHelper) GetOutputFormat

func (_m *MockHelper) GetOutputFormat() (common.OutputFormat, error)

GetOutputFormat provides a mock function with no fields

func (*MockHelper) GetProduct

func (_m *MockHelper) GetProduct() (products.ProductValue, error)

GetProduct provides a mock function with no fields

func (*MockHelper) GetStreams

func (_m *MockHelper) GetStreams() *iostreams.IOStreams

GetStreams provides a mock function with no fields

func (*MockHelper) GetVerb

func (_m *MockHelper) GetVerb() (verbs.VerbValue, error)

GetVerb provides a mock function with no fields

type MockHelper_Expecter

type MockHelper_Expecter struct {
	// contains filtered or unexported fields
}

func (*MockHelper_Expecter) GetArgs

GetArgs is a helper method to define mock.On call

func (*MockHelper_Expecter) GetBuildInfo

GetBuildInfo is a helper method to define mock.On call

func (*MockHelper_Expecter) GetCmd

GetCmd is a helper method to define mock.On call

func (*MockHelper_Expecter) GetConfig

GetConfig is a helper method to define mock.On call

func (*MockHelper_Expecter) GetContext

GetContext is a helper method to define mock.On call

func (*MockHelper_Expecter) GetKonnectSDK added in v0.0.13

func (_e *MockHelper_Expecter) GetKonnectSDK(cfg interface{}, logger interface{}) *MockHelper_GetKonnectSDK_Call

GetKonnectSDK is a helper method to define mock.On call

  • cfg config.Hook
  • logger *slog.Logger

func (*MockHelper_Expecter) GetLogger

GetLogger is a helper method to define mock.On call

func (*MockHelper_Expecter) GetOutputFormat

GetOutputFormat is a helper method to define mock.On call

func (*MockHelper_Expecter) GetProduct

GetProduct is a helper method to define mock.On call

func (*MockHelper_Expecter) GetStreams

GetStreams is a helper method to define mock.On call

func (*MockHelper_Expecter) GetVerb

GetVerb is a helper method to define mock.On call

type MockHelper_GetArgs_Call

type MockHelper_GetArgs_Call struct {
	*mock.Call
}

MockHelper_GetArgs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetArgs'

func (*MockHelper_GetArgs_Call) Return

func (*MockHelper_GetArgs_Call) Run

func (_c *MockHelper_GetArgs_Call) Run(run func()) *MockHelper_GetArgs_Call

func (*MockHelper_GetArgs_Call) RunAndReturn

func (_c *MockHelper_GetArgs_Call) RunAndReturn(run func() []string) *MockHelper_GetArgs_Call

type MockHelper_GetBuildInfo_Call

type MockHelper_GetBuildInfo_Call struct {
	*mock.Call
}

MockHelper_GetBuildInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetBuildInfo'

func (*MockHelper_GetBuildInfo_Call) Return

func (*MockHelper_GetBuildInfo_Call) Run

func (*MockHelper_GetBuildInfo_Call) RunAndReturn

func (_c *MockHelper_GetBuildInfo_Call) RunAndReturn(run func() (*build.Info, error)) *MockHelper_GetBuildInfo_Call

type MockHelper_GetCmd_Call

type MockHelper_GetCmd_Call struct {
	*mock.Call
}

MockHelper_GetCmd_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetCmd'

func (*MockHelper_GetCmd_Call) Return

func (*MockHelper_GetCmd_Call) Run

func (_c *MockHelper_GetCmd_Call) Run(run func()) *MockHelper_GetCmd_Call

func (*MockHelper_GetCmd_Call) RunAndReturn

func (_c *MockHelper_GetCmd_Call) RunAndReturn(run func() *cobra.Command) *MockHelper_GetCmd_Call

type MockHelper_GetConfig_Call

type MockHelper_GetConfig_Call struct {
	*mock.Call
}

MockHelper_GetConfig_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetConfig'

func (*MockHelper_GetConfig_Call) Return

func (*MockHelper_GetConfig_Call) Run

func (*MockHelper_GetConfig_Call) RunAndReturn

func (_c *MockHelper_GetConfig_Call) RunAndReturn(run func() (config.Hook, error)) *MockHelper_GetConfig_Call

type MockHelper_GetContext_Call

type MockHelper_GetContext_Call struct {
	*mock.Call
}

MockHelper_GetContext_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetContext'

func (*MockHelper_GetContext_Call) Return

func (*MockHelper_GetContext_Call) Run

func (*MockHelper_GetContext_Call) RunAndReturn

type MockHelper_GetKonnectSDK_Call added in v0.0.13

type MockHelper_GetKonnectSDK_Call struct {
	*mock.Call
}

MockHelper_GetKonnectSDK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetKonnectSDK'

func (*MockHelper_GetKonnectSDK_Call) Return added in v0.0.13

func (*MockHelper_GetKonnectSDK_Call) Run added in v0.0.13

func (*MockHelper_GetKonnectSDK_Call) RunAndReturn added in v0.0.13

type MockHelper_GetLogger_Call

type MockHelper_GetLogger_Call struct {
	*mock.Call
}

MockHelper_GetLogger_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetLogger'

func (*MockHelper_GetLogger_Call) Return

func (*MockHelper_GetLogger_Call) Run

func (*MockHelper_GetLogger_Call) RunAndReturn

func (_c *MockHelper_GetLogger_Call) RunAndReturn(run func() (*slog.Logger, error)) *MockHelper_GetLogger_Call

type MockHelper_GetOutputFormat_Call

type MockHelper_GetOutputFormat_Call struct {
	*mock.Call
}

MockHelper_GetOutputFormat_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetOutputFormat'

func (*MockHelper_GetOutputFormat_Call) Return

func (*MockHelper_GetOutputFormat_Call) Run

func (*MockHelper_GetOutputFormat_Call) RunAndReturn

type MockHelper_GetProduct_Call

type MockHelper_GetProduct_Call struct {
	*mock.Call
}

MockHelper_GetProduct_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetProduct'

func (*MockHelper_GetProduct_Call) Return

func (*MockHelper_GetProduct_Call) Run

func (*MockHelper_GetProduct_Call) RunAndReturn

type MockHelper_GetStreams_Call

type MockHelper_GetStreams_Call struct {
	*mock.Call
}

MockHelper_GetStreams_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetStreams'

func (*MockHelper_GetStreams_Call) Return

func (*MockHelper_GetStreams_Call) Run

func (*MockHelper_GetStreams_Call) RunAndReturn

type MockHelper_GetVerb_Call

type MockHelper_GetVerb_Call struct {
	*mock.Call
}

MockHelper_GetVerb_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetVerb'

func (*MockHelper_GetVerb_Call) Return

func (*MockHelper_GetVerb_Call) Run

func (_c *MockHelper_GetVerb_Call) Run(run func()) *MockHelper_GetVerb_Call

func (*MockHelper_GetVerb_Call) RunAndReturn

func (_c *MockHelper_GetVerb_Call) RunAndReturn(run func() (verbs.VerbValue, error)) *MockHelper_GetVerb_Call

Jump to

Keyboard shortcuts

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