Help us shape the future of Go! Take the 2026 Go Developer Survey

app

package
v0.30.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package app provides the execution context for stackit commands.

It encapsulates shared dependencies and configuration needed by actions, such as the engine instance, logger, and repository root path. This avoids passing multiple parameters throughout the application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	context.Context
	Engine       engine.Engine
	Output       output.Output
	Logger       output.Logger
	RepoRoot     string
	GitHubClient github.Client
	Config       config.Configurer // Cached config to avoid repeated loading

	// GHRunner is the narrow git surface the GitHub integration needs (git
	// config reads and gh CLI execution). It is set at construction so actions
	// never reach through the engine to the raw git runner.
	GHRunner github.GitCommandRunner

	// Prompter is the adapter-supplied implementation of the generic
	// interactive prompts (confirm, select, text input, multi-select).
	// Actions read it through Prompts(), which falls back to a prompter that
	// reports interactivity as disabled when no adapter set one.
	Prompter handler.Prompter

	// Global settings from flags
	Interactive bool
	Verify      bool
	Debug       bool
	Quiet       bool

	// Worktree context
	InManagedWorktree bool                 // True if running from a stackit-managed worktree
	WorktreeInfo      *engine.WorktreeInfo // Info about current worktree (nil if not in managed worktree)
	// contains filtered or unexported fields
}

Context provides access to engine and output for commands

func GetContext

func GetContext(ctx context.Context, opts GlobalOptions) (*Context, error)

GetContext returns the appropriate context (demo or real) based on the environment. This handles git initialization and config checks for real mode.

func GetContextWithWriter

func GetContextWithWriter(ctx context.Context, opts GlobalOptions, writer io.Writer) (*Context, error)

GetContextWithWriter is like GetContext but allows specifying the output writer.

func NewContext

func NewContext(eng engine.Engine, opts ...ContextOption) *Context

NewContext creates a new context with the given engine and options

func NewContextAutoWithWriter

func NewContextAutoWithWriter(ctx context.Context, repoRoot string, opts GlobalOptions, writer io.Writer) (*Context, error)

NewContextAutoWithWriter is like NewContextAuto but allows specifying the output writer.

func (*Context) Absorb

func (c *Context) Absorb() engine.Absorber

Absorb returns the absorb manager from the engine.

func (*Context) GetUserName added in v0.19.1

func (c *Context) GetUserName(ctx context.Context) (string, error)

GetUserName returns the configured git user name. Forwards to the engine so callers that only need the username (e.g. branch-name patterns) can depend on this instead of the full git runner.

func (*Context) GitHub

func (c *Context) GitHub() github.Client

GitHub returns the GitHub client, lazily initializing it on first access. If GitHubClient was set directly (e.g. in tests), it is returned immediately. Returns nil if initialization failed; use GitHubError() to get the reason.

func (*Context) GitHubError

func (c *Context) GitHubError() error

GitHubError returns the error from lazy GitHub client initialization, if any.

func (*Context) History

func (c *Context) History() engine.StackRewriter

History returns the history rewriter from the engine.

func (*Context) Info

func (c *Context) Info() engine.BranchInfo

Info returns the branch info provider from the engine.

func (*Context) Navigator

func (c *Context) Navigator() engine.StackNavigator

Navigator returns the stack navigator from the engine.

func (*Context) PR

func (c *Context) PR() engine.PRManager

PR returns the PR manager from the engine.

func (*Context) Prompts added in v0.29.0

func (c *Context) Prompts() handler.Prompter

Prompts returns the adapter-supplied prompter, or a non-interactive one whose prompts fail with term.ErrInteractiveDisabled when none was set.

func (*Context) Reader

func (c *Context) Reader() engine.BranchReader

Reader returns the branch reader from the engine.

func (*Context) RemoteMetadata

func (c *Context) RemoteMetadata() engine.RemoteMetadataManager

RemoteMetadata returns the remote metadata manager from the engine.

func (*Context) RemoteOperationContext added in v0.20.0

func (c *Context) RemoteOperationContext() (context.Context, context.CancelFunc)

RemoteOperationContext returns a child context for explicit remote work. It preserves an existing command deadline; otherwise it applies Stackit's standard remote-operation timeout.

func (*Context) RequireGitHub

func (c *Context) RequireGitHub() (github.Client, error)

RequireGitHub returns the GitHub client or an error explaining why it's unavailable. Use this instead of checking GitHub() == nil manually.

func (*Context) Status

func (c *Context) Status() engine.BranchStatus

Status returns the branch status provider from the engine.

func (*Context) Sync

func (c *Context) Sync() engine.SyncManager

Sync returns the sync manager from the engine.

func (*Context) Undo

func (c *Context) Undo() engine.UndoManager

Undo returns the undo manager from the engine.

func (*Context) Worktree

func (c *Context) Worktree() engine.WorktreeRegistry

Worktree returns the worktree registry from the engine.

func (*Context) Writer

func (c *Context) Writer() engine.BranchWriter

Writer returns the branch writer from the engine.

type ContextOption

type ContextOption func(*contextOptions)

ContextOption is a function that configures a Context

func WithGitHubRunner added in v0.29.0

func WithGitHubRunner(runner github.GitCommandRunner) ContextOption

WithGitHubRunner sets the runner the GitHub integration uses to read git config and execute gh commands.

func WithGlobalOptions

func WithGlobalOptions(opts GlobalOptions) ContextOption

WithGlobalOptions sets the global options

func WithInteractive

func WithInteractive(interactive bool) ContextOption

WithInteractive sets the interactive mode

func WithLogger

func WithLogger(logger output.Logger) ContextOption

WithLogger sets the logger

func WithRepoRoot

func WithRepoRoot(repoRoot string) ContextOption

WithRepoRoot sets the repository root path

func WithWriter

func WithWriter(writer io.Writer) ContextOption

WithWriter sets the output writer

type GlobalOptions

type GlobalOptions struct {
	Interactive              bool
	Verify                   bool
	Debug                    bool
	Quiet                    bool
	Cwd                      string
	EngineLoadMode           *engine.LoadMode
	SkipManagedWorktreeCheck bool
}

GlobalOptions holds settings from global flags

func GetDefaultGlobalOptions

func GetDefaultGlobalOptions() GlobalOptions

GetDefaultGlobalOptions returns default options

Directories

Path Synopsis
Package actiondeps builds the collaborators each action takes from the CLI's runtime context.
Package actiondeps builds the collaborators each action takes from the CLI's runtime context.

Jump to

Keyboard shortcuts

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