cmdutil

package
v0.1.23 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: Apache-2.0 Imports: 21 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// MaxReaderLimitSize is the upper limit for reader capability.
	MaxReaderLimitSize = 25 * 1024 * 1024
	// ReaderTimeout is a time limit during the reader is waiting for data.
	ReaderTimeout = 1 * time.Minute
)

Variables

View Source
var ErrNoHome = errors.New("no home found")

ErrNoHome is raised when tilde expansion failed.

Functions

func BugReport

func BugReport() string

BugReport generates a bug report body

func Context

func Context(ctx context.Context, name string, debug bool, logLevel string) (context.Context, context.CancelFunc)

Context initializes a command context.

func Expand

func Expand(path string) (string, error)

Expand a given path using `~` notation for HOMEDIR

func FileReader

func FileReader(filename string) func(context.Context) (io.Reader, error)

FileReader returns lazy evaluated reader.

func FileWriter

func FileWriter(filename string) func(context.Context) (io.Writer, error)

FileWriter returns lazy evaluated writer.

func HandlePluginCommand

func HandlePluginCommand(pluginHandler PluginHandler, cmdArgs []string) error

HandlePluginCommand receives a pluginHandler and command-line arguments and attempts to find a plugin executable on the PATH that satisfies the given arguments.

func LineReader

func LineReader(name string) ([]string, error)

LineReader creates a reder and returns content read line by line.

func NewTimeoutReader

func NewTimeoutReader(reader io.Reader, timeout time.Duration) io.Reader

NewTimeoutReader create a timed-out limited reader instance.

func ReadSecret

func ReadSecret(prompt string, confirmation bool) (*memguard.LockedBuffer, error)

ReadSecret reads password from Stdin and returns a lockedbuffer.

func Reader

func Reader(name string) (io.Reader, error)

Reader creates a reader instance according to the given name value Use "" or "-" for Stdin reader, else use a filename.

func StdoutWriter

func StdoutWriter() func(context.Context) (io.Writer, error)

StdoutWriter returns lazy evaluated writer.

func Writer

func Writer(name string) (io.Writer, error)

Writer creates a writer according to the given name value Use "" or "-" for Stdout writer, else use a filename.

Types

type DefaultPluginHandler

type DefaultPluginHandler struct {
	ValidPrefixes []string
}

DefaultPluginHandler implements PluginHandler

func NewDefaultPluginHandler

func NewDefaultPluginHandler(validPrefixes []string) *DefaultPluginHandler

NewDefaultPluginHandler instantiates the DefaultPluginHandler with a list of given filename prefixes used to identify valid plugin filenames.

func (*DefaultPluginHandler) Execute

func (h *DefaultPluginHandler) Execute(executablePath string, cmdArgs, environment []string) error

Execute implements PluginHandler

func (*DefaultPluginHandler) Lookup

func (h *DefaultPluginHandler) Lookup(filename string) (string, bool)

Lookup implements PluginHandler

type PluginHandler

type PluginHandler interface {
	// exists at the given filename, or a boolean false.
	// Lookup will iterate over a list of given prefixes
	// in order to recognize valid plugin filenames.
	// The first filepath to match a prefix is returned.
	Lookup(filename string) (string, bool)
	// Execute receives an executable's filepath, a slice
	// of arguments, and a slice of environment variables
	// to relay to the executable.
	Execute(executablePath string, cmdArgs, environment []string) error
}

PluginHandler is capable of parsing command line arguments and performing executable filename lookups to search for valid plugin files, and execute found plugins.

type TimeoutReader

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

TimeoutReader implemnts a timelimited reader.

func (*TimeoutReader) Read

func (r *TimeoutReader) Read(buf []byte) (n int, err error)

Read implements io.Reader interface.

Jump to

Keyboard shortcuts

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