shell

package
v0.0.0-...-9e26561 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: Apache-2.0 Imports: 11 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCantGetCaller is raised when we can't calculate a caller of NewProjectLocation.
	ErrCantGetCaller = errors.New("can't get caller")

	// ErrCallerNotAllowed is raised when user tries to use this shell-out package
	// outside of allowed places. This package is deprecated from start and was
	// introduced to allow rewriting of shell code to Golang in small chunks.
	ErrCallerNotAllowed = errors.New("don't try use knative.dev/pkg/test/upgrade/shell package outside of allowed places")
)

Functions

func NewPrefixer

func NewPrefixer(writer io.Writer, prefix func() string) io.Writer

NewPrefixer creates a new prefixer that forwards all calls to Write() to writer.Write() with all lines prefixed with the value of prefix. Having a function instead of a static prefix allows to print timestamps or other changing information.

Types

type Executor

type Executor interface {
	RunScript(script Script, args ...string) error
	RunFunction(fn Function, args ...string) error
}

Executor represents a executor that can execute shell scripts and call functions directly.

func NewExecutor

func NewExecutor(t TestingT, loc ProjectLocation, opts ...Option) Executor

NewExecutor creates a new executor.

type ExecutorConfig

type ExecutorConfig struct {
	ProjectLocation
	Streams
	Labels
	Environ []string
}

ExecutorConfig holds executor configuration options.

type Function

type Function struct {
	Script
	FunctionName string
}

Function represents a function, whom will be sourced from Script file, and executed.

type Labels

type Labels struct {
	LabelOut   string
	LabelErr   string
	SkipDate   bool
	DateFormat string
	PrefixFunc
}

Labels holds a labels to be used to prefix Out and Err streams of executed shells scripts/functions.

type Option

type Option func(*ExecutorConfig)

Option overrides configuration options in ExecutorConfig.

type PrefixFunc

type PrefixFunc func(st StreamType, label string, config ExecutorConfig) string

PrefixFunc is used to build a prefix that will be added to each line of the script/function output or error stream.

type ProjectLocation

type ProjectLocation interface {
	RootPath() string
}

ProjectLocation represents a project location on a file system.

func NewProjectLocation

func NewProjectLocation(pathToRoot string) (ProjectLocation, error)

NewProjectLocation creates a ProjectLocation that is used to calculate relative paths within the project.

type Script

type Script struct {
	Label      string
	ScriptPath string
}

Script represents a script to be executed.

type StreamType

type StreamType int

StreamType represets either output or error stream.

const (
	// StreamTypeOut represents process output stream.
	StreamTypeOut StreamType = iota
	// StreamTypeErr represents process error stream.
	StreamTypeErr
)

type Streams

type Streams struct {
	Out io.Writer
	Err io.Writer
}

Streams holds a streams of a shell scripts/functions.

type TestingT

type TestingT interface {
	Logf(format string, args ...any)
}

TestingT is used by testingWriter and allows passing testing.T.

Jump to

Keyboard shortcuts

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