cmdutil

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

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

Variables

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

ErrNoHome is raised when tilde expansion failed.

Functions

func BugReport

func BugReport() string

func Context

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

Context initializes a command context.

func DirectWriter

func DirectWriter(w io.Writer) func(context.Context) (io.Writer, error)

DirectWriter returns the given writer.

func DiscardWriter

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

DiscardWriter returns discard writer.

func Examples

func Examples(s string) string

Examples normalizes a command's examples to follow the conventions.

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 LongDesc

func LongDesc(s string) string

LongDesc normalizes a command's long description to follow the conventions.

func NewClosedWriter

func NewClosedWriter() io.WriteCloser

NewClosedWriter returns a io.WriteCloser instance which always fails when writing data. (Used for testing purpose).

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.WriteCloser, 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