util

package
v0.0.0-...-d889ebb Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterStringsByPrefix

func FilterStringsByPrefix(prefix string, values []string) []string

func NewTestIOStreams

func NewTestIOStreams() (IOStreams, *SafeBytesBuffer, *SafeBytesBuffer, *SafeBytesBuffer)

NewTestIOStreams returns a valid IOStreams and in, out, errout buffers for unit tests.

func ShellEscape

func ShellEscape(values ...interface{}) string

ShellEscape returns a shell-escaped version of the given string. It also removes non-printable characters.

func StripUnsafe

func StripUnsafe(s string) string

StripUnsafe remove non-printable characters from the string.

Types

type Clock

type Clock interface {
	// Now returns the current time
	Now() time.Time
}

Clock provides the current time.

type Factory

type Factory interface {
	// Context returns the root context any command should use.
	Context() context.Context
	// Clock returns a clock that provides access to the current time.
	Clock() Clock
	// GardenHomeDir returns the gardenctl home directory for the executing user.
	GardenHomeDir() string
	// Manager returns the target manager used to read and change the currently targeted system.
	Manager() (target.Manager, error)
	// PublicIPs returns the current host's public IP addresses. It's
	// recommended to provide a context with a timeout/deadline. The
	// returned slice can contain IPv6, IPv4 or both, in no particular
	// order.
	PublicIPs(context.Context) ([]string, error)
	// TargetFlags returns the TargetFlags to which the cobra flags are bound allowing the user to
	// override the target configuration stored on the filesystem.
	TargetFlags() target.TargetFlags
}

Factory provides abstractions that allow the command to be extended across multiple types of resources and different API sets.

type FactoryImpl

type FactoryImpl struct {
	// GardenHomeDirectory is the home directory for all gardenctl
	// related files. While some files can be explicitly loaded from
	// different locations, cache files will always be placed inside
	// the garden home.
	GardenHomeDirectory string

	// ConfigFile is the location of the gardenctlv2 configuration file.
	// This can be overridden via a CLI flag and defaults to ~/.garden/gardenctlv2.yaml
	// if empty.
	ConfigFile string
	// contains filtered or unexported fields
}

FactoryImpl implements util.Factory interface.

func NewFactoryImpl

func NewFactoryImpl() *FactoryImpl

func (*FactoryImpl) Clock

func (f *FactoryImpl) Clock() Clock

func (*FactoryImpl) Context

func (f *FactoryImpl) Context() context.Context

func (*FactoryImpl) GardenHomeDir

func (f *FactoryImpl) GardenHomeDir() string

func (*FactoryImpl) Manager

func (f *FactoryImpl) Manager() (target.Manager, error)

func (*FactoryImpl) PublicIPs

func (f *FactoryImpl) PublicIPs(ctx context.Context) ([]string, error)

func (*FactoryImpl) TargetFlags

func (f *FactoryImpl) TargetFlags() target.TargetFlags

type IOStreams

type IOStreams struct {
	// In think, os.Stdin
	In io.Reader
	// Out think, os.Stdout
	Out io.Writer
	// ErrOut think, os.Stderr
	ErrOut io.Writer
}

IOStreams provides the standard names for iostreams. This is useful for embedding and for unit testing. Inconsistent and different names make it hard to read and review code.

func NewIOStreams

func NewIOStreams() IOStreams

NewIOStreams returns a valid IOStreams and with the default stdin/out/err streams.

type RealClock

type RealClock struct{}

RealClock implements Clock interface.

func (RealClock) Now

func (RealClock) Now() time.Time

type SafeBytesBuffer

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

SafeBytesBuffer is a bytes.Buffer that is safe for use in multiple goroutines.

func (*SafeBytesBuffer) Read

func (s *SafeBytesBuffer) Read(p []byte) (n int, err error)

Read reads the next len(p) bytes from the buffer or until the buffer is drained. The return value n is the number of bytes read. If the buffer has no data to return, err is io.EOF (unless len(p) is zero); otherwise it is nil.

func (*SafeBytesBuffer) String

func (s *SafeBytesBuffer) String() string

String returns the contents of the unread portion of the buffer as a string. If the Buffer is a nil pointer, it returns "<nil>".

To build strings more efficiently, see the strings.Builder type.

func (*SafeBytesBuffer) Write

func (s *SafeBytesBuffer) Write(p []byte) (n int, err error)

Write appends the contents of p to the buffer, growing the buffer as needed. The return value n is the length of p; err is always nil. If the buffer becomes too large, Write will panic with ErrTooLarge.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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