run

package
v0.48.3 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package run holds the run.Run construct, which encapsulates CLI state for a command execution.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, ru *Run) context.Context

NewContext returns ctx with ru added as a value.

func NewQueryContext

func NewQueryContext(ru *Run, args map[string]string) *libsq.QueryContext

NewQueryContext returns a *libsq.QueryContext constructed from ru.

Types

type Run

type Run struct {
	// Out is the output destination, typically a decorated writer over
	// [Run.Stdout]. This writer should generally be used for program output,
	// not [Run.Stdout].
	Out io.Writer

	// Stdout is the original stdout file descriptor, which is typically
	// the actual os.Stdout. Output should generally be written to [Run.Out]
	// except for a few rare circumstances, such as executing an external
	// program.
	Stdout io.Writer

	// ErrOut is the error output destination, typically a decorated writer
	// over [Run.Stderr]. This writer should generally be used for error output,
	// not [Run.Stderr].
	ErrOut io.Writer

	// Stderr is the original stderr file descriptor, which is typically
	// the actual os.Stderr. Error output should generally be written to
	// [Run.ErrOut] except for a few rare circumstances, such as executing an
	// external program.
	Stderr io.Writer

	// ConfigStore manages config persistence.
	ConfigStore config.Store

	// Stdin typically is os.Stdin, but can be changed for testing.
	Stdin *os.File

	// Cmd is the command instance provided by cobra for
	// the currently executing command. This field will
	// be set before the command's runFunc is invoked.
	Cmd *cobra.Command

	// Config is the run's config.
	Config *config.Config

	// OptionsRegistry is a registry of CLI options.Opt instances.
	OptionsRegistry *options.Registry

	// DriverRegistry is a registry of driver implementations.
	DriverRegistry *driver.Registry

	// Files manages file access.
	Files *files.Files

	// Grips mediates access to driver.Grip instances.
	Grips *driver.Grips

	// MDCache caches source metadata.
	MDCache *mdcache.Cache

	// Writers holds the various writer types that
	// the CLI uses to print output.
	Writers *output.Writers

	// Cleanup holds cleanup functions, except log closing, which
	// is held by LogCloser.
	Cleanup *cleanup.Cleanup

	// LogCloser contains any log-closing action (such as closing
	// a log file). It may be nil. Execution of this function
	// should be more-or-less the final cleanup action performed by the CLI,
	// and absolutely must happen after all other cleanup actions.
	LogCloser func() error

	// Args is the arg slice supplied by cobra for
	// the currently executing command. This field will
	// be set before the command's runFunc is invoked.
	Args []string
}

Run is a container for injectable resources passed to all cobra exec funcs. The Close method should be invoked when the Run is no longer needed.

func FromContext

func FromContext(ctx context.Context) *Run

FromContext extracts the Run added to ctx via NewContext.

func (*Run) Close

func (ru *Run) Close() error

Close should be invoked to dispose of any open resources held by ru. If an error occurs during Close and ru.Log is not nil, that error is logged at WARN level before being returned. Note that Run.LogCloser must be invoked separately.

func (*Run) DB added in v0.47.4

func (ru *Run) DB(ctx context.Context, src *source.Source) (sqlz.DB, driver.SQLDriver, error)

DB is a convenience method that gets the sqlz.DB and driver.SQLDriver for src.

Jump to

Keyboard shortcuts

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