app

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 13 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

View Source
const DefaultRemoteOperationTimeout = 5 * time.Minute

DefaultRemoteOperationTimeout bounds explicit remote operations launched by commands when the parent command context does not already carry a deadline.

Variables

View Source
var DemoEngineFactory func() engine.Engine

DemoEngineFactory is a function that creates a demo engine. This is set by the demo package to avoid circular imports.

View Source
var DemoGitHubClientFactory func() github.Client

DemoGitHubClientFactory is a function that creates a demo GitHub client. This is set by the demo package to avoid circular imports.

Functions

func WithRemoteOperationTimeout added in v0.20.0

func WithRemoteOperationTimeout(parent context.Context) (context.Context, context.CancelFunc)

WithRemoteOperationTimeout applies the default remote-operation timeout only when the parent context has no deadline. The returned cancel function should always be called by the caller.

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

	// 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 NewContextAuto

func NewContextAuto(ctx context.Context, repoRoot string, opts GlobalOptions) (*Context, error)

NewContextAuto creates a context automatically based on the environment. In demo mode, it creates a demo engine. Otherwise, it creates a real engine using the provided repoRoot.

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) Git

func (c *Context) Git() git.Runner

Git returns the git runner from the engine. Panics if the Engine is nil, which indicates a programming error.

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) 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 WithDebug

func WithDebug(debug bool) ContextOption

WithDebug sets the debug mode

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 WithQuiet

func WithQuiet(quiet bool) ContextOption

WithQuiet sets the quiet mode

func WithRepoRoot

func WithRepoRoot(repoRoot string) ContextOption

WithRepoRoot sets the repository root path

func WithVerify

func WithVerify(verify bool) ContextOption

WithVerify sets the verify mode

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

Jump to

Keyboard shortcuts

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