Documentation
¶
Index ¶
- func ClientFromCmd(cmd *cobra.Command) (kukeonv1.Client, error)
- func ControllerFromCmd(cmd *cobra.Command) (*controller.Exec, error)
- func FormatValidationErrors(validationErrors []*parser.ValidationError) error
- func GetControllerWithMock[T any](cmd *cobra.Command, mockKey any, ...) (T, error)
- func GetControllerWithMockWrapper[T any](cmd *cobra.Command, mockKey any, wrapper func(*controller.Exec) T) (T, error)
- func LoggerFromCmd(cmd *cobra.Command) (*slog.Logger, error)
- func ParseAndValidateDocuments(reader io.Reader) ([]parser.Document, []*parser.ValidationError, error)
- func PrintJSONOrYAML(cmd *cobra.Command, data interface{}, format string) error
- func ReadFileOrStdin(file string) (io.Reader, func() error, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClientFromCmd ¶
ClientFromCmd returns a kukeonv1.Client selected by flags/env:
- --no-daemon (or KUKEON_NO_DAEMON=true): in-process Client backed by a fresh controller.Exec. Requires privileges.
- default: JSON-RPC Client dialing KUKEON_HOST (unix:///... today).
The caller owns the returned Client and must Close it.
func ControllerFromCmd ¶
func ControllerFromCmd(cmd *cobra.Command) (*controller.Exec, error)
ControllerFromCmd instantiates a controller.Exec configured with the shared persistent flags (run path, containerd socket) used by the parent command.
func FormatValidationErrors ¶
func FormatValidationErrors(validationErrors []*parser.ValidationError) error
FormatValidationErrors formats validation errors into a single error message. If all errors are parsing errors (contain "failed to parse"), it returns a YAML parsing error instead of a validation error.
func GetControllerWithMock ¶
func GetControllerWithMock[T any]( cmd *cobra.Command, mockKey any, realController func(*cobra.Command) (T, error), ) (T, error)
GetControllerWithMock is a generic helper to get a controller from context, supporting mock injection via a context key. If a mock is found in the context, it is returned. Otherwise, a real controller is created using ControllerFromCmd. The mockKey should be a unique type used as the context key.
func GetControllerWithMockWrapper ¶
func GetControllerWithMockWrapper[T any](cmd *cobra.Command, mockKey any, wrapper func(*controller.Exec) T) (T, error)
GetControllerWithMockWrapper is a convenience function that wraps GetControllerWithMock to use ControllerFromCmd as the real controller factory.
func LoggerFromCmd ¶
LoggerFromCmd extracts the slog logger from the Cobra command context.
func ParseAndValidateDocuments ¶
func ParseAndValidateDocuments(reader io.Reader) ([]parser.Document, []*parser.ValidationError, error)
ParseAndValidateDocuments parses and validates YAML documents from a reader. Returns the parsed documents and any validation errors encountered. If there are validation errors, they are returned as a slice, but the function still returns the successfully parsed documents.
func PrintJSONOrYAML ¶
PrintJSONOrYAML prints data in JSON or YAML format. The data parameter should be a struct that can be marshaled.
Types ¶
This section is empty.