context

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const HeaderCtxKey = "ctx"

Variables

This section is empty.

Functions

func ExpandRef

func ExpandRef(ctx *Context, ref executable.Ref) executable.Ref

func ExpandRefFromParent

func ExpandRefFromParent(parent *executable.Executable, ref executable.Ref) executable.Ref

Types

type Context

type Context struct {
	Config           *config.Config
	CurrentWorkspace *workspace.Workspace
	WorkspacesCache  cache.WorkspaceCache
	ExecutableCache  cache.ExecutableCache
	DataStore        store.DataStore

	// RootExecutable is the executable that is being run in the current context.
	// This will be nil if the context is not associated with an executable run.
	RootExecutable *executable.Executable

	// ProcessTmpDir is the temporary directory for the current process. If set, it will be
	// used to store temporary files all executable runs when the tmpDir value is specified.
	ProcessTmpDir string

	// CurrentTask holds the task context for the currently executing step in a
	// parallel or serial runner. It is set per-goroutine (via shallow copy) so
	// that downstream writers can prefix output with the task name.
	CurrentTask *io.TaskContext

	// LogArchiveID is the unique identifier used in the log archive filename for
	// this process. It is set at startup and used to link execution records to
	// their log output.
	LogArchiveID string
	// contains filtered or unexported fields
}

func NewContext

func NewContext(ctx context.Context, cancelFunc context.CancelFunc, opts ...Option) *Context

func (*Context) AddCallback

func (ctx *Context) AddCallback(callback func(*Context) error)

func (*Context) AppName

func (ctx *Context) AppName() string

func (*Context) Cancel

func (ctx *Context) Cancel()

func (*Context) Deadline

func (ctx *Context) Deadline() (deadline time.Time, ok bool)

func (*Context) Done

func (ctx *Context) Done() <-chan struct{}

func (*Context) Err

func (ctx *Context) Err() error

func (*Context) Finalize

func (ctx *Context) Finalize()

func (*Context) SetContext

func (ctx *Context) SetContext(c context.Context, cancelFunc context.CancelFunc)

SetContext sets the context and cancel function for the Context. This function should NOT be used outside of tests! The context and cancel function should be set when creating the context.

func (*Context) SetIO

func (ctx *Context) SetIO(stdIn, stdOut *os.File)

SetIO sets the standard input and output for the context This function should NOT be used outside of tests! The standard input and output should be set when creating the context.

func (*Context) SetStdErr

func (ctx *Context) SetStdErr(stdErr *os.File)

SetStdErr sets the standard error file. Intended for tests.

func (*Context) SetTUIContainer

func (ctx *Context) SetTUIContainer(c *tuikit.Container)

SetTUIContainer sets the TUI container directly, bypassing lazy init. This is intended for tests that provide a pre-built container.

func (*Context) SetView

func (ctx *Context) SetView(view tuikit.View) error

func (*Context) ShallowCopy

func (ctx *Context) ShallowCopy() *Context

ShallowCopy returns a pointer to a new Context that shares all backing state (config, caches, data store, TUI container) but has its own mutable fields (CurrentTask, ProcessTmpDir, etc.)

func (*Context) StdErr

func (ctx *Context) StdErr() *os.File

StdErr returns the standard error file for structured error envelopes. Falls back to os.Stderr when unset (e.g. in tests that bypass NewContext).

func (*Context) StdIn

func (ctx *Context) StdIn() *os.File

func (*Context) StdOut

func (ctx *Context) StdOut() *os.File

func (*Context) String

func (ctx *Context) String() string

func (*Context) TUIContainer

func (ctx *Context) TUIContainer() *tuikit.Container

TUIContainer returns the TUI container, initializing it on first access. This avoids eagerly creating a bubbletea program (which reads terminal state from stdin) for commands that never use the TUI.

func (*Context) Value

func (ctx *Context) Value(key any) any

TODO: Move access to various context fields to this function

type Option

type Option func(*Context)

Option configures optional fields on a Context during construction.

func WithAppName

func WithAppName(name string) Option

func WithStdErr

func WithStdErr(f *os.File) Option

WithStdErr sets the standard error file. Defaults to os.Stderr.

func WithStdIn

func WithStdIn(f *os.File) Option

WithStdIn sets the standard input file. Defaults to os.Stdin.

func WithStdOut

func WithStdOut(f *os.File) Option

WithStdOut sets the standard output file. Defaults to os.Stdout.

Jump to

Keyboard shortcuts

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