shared

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientFromCmd

func ClientFromCmd(cmd *cobra.Command) (kukeonv1.Client, error)

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

func LoggerFromCmd(cmd *cobra.Command) (*slog.Logger, error)

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

func PrintJSONOrYAML(cmd *cobra.Command, data interface{}, format string) error

PrintJSONOrYAML prints data in JSON or YAML format. The data parameter should be a struct that can be marshaled.

func ReadFileOrStdin

func ReadFileOrStdin(file string) (io.Reader, func() error, error)

ReadFileOrStdin reads from a file or stdin if file is "-". Returns the reader and a cleanup function that should be called when done. If file is "-", the cleanup function is a no-op.

Types

This section is empty.

Jump to

Keyboard shortcuts

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