appctx

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package appctx provides application context helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithApp

func WithApp(ctx context.Context, app *App) context.Context

WithApp stores the app in the context.

Types

type App

type App struct {
	Config *config.Config
	Auth   *auth.Manager
	SDK    *basecamp.Client
	Names  *names.Resolver
	Output *output.Writer

	// Observability
	Collector *observability.SessionCollector
	Hooks     *observability.CLIHooks

	// Flags holds the global flag values
	Flags GlobalFlags
}

App holds the shared application context for all commands.

func FromContext

func FromContext(ctx context.Context) *App

FromContext retrieves the app from the context.

func NewApp

func NewApp(cfg *config.Config) *App

NewApp creates a new App with the given configuration.

func (*App) Account

func (a *App) Account() *basecamp.AccountClient

Account returns an account-scoped client for the configured account. This is the preferred way to access the SDK for operations that require an account context (projects, todos, people, etc.).

Call RequireAccount() first to validate the account is properly configured. ForAccount() will panic if accountID is empty or non-numeric.

For account-agnostic operations (like Authorization().GetInfo()), use app.SDK directly.

func (*App) ApplyFlags

func (a *App) ApplyFlags()

ApplyFlags applies global flag values to the app configuration.

func (*App) Err

func (a *App) Err(err error) error

Err outputs an error response, including stats in the envelope for JSON/Markdown or printing to stderr for styled output.

func (*App) IsInteractive

func (a *App) IsInteractive() bool

IsInteractive returns true if the terminal supports interactive TUI.

func (*App) IsMachineOutput

func (a *App) IsMachineOutput() bool

IsMachineOutput returns true if the output mode is intended for programmatic consumption. Checks both flags and config-driven format settings. Use this to suppress human-friendly notices (like truncation warnings) in machine output.

func (*App) OK

func (a *App) OK(data any, opts ...output.ResponseOption) error

OK outputs a success response, automatically including stats if --stats flag is set.

func (*App) RequireAccount

func (a *App) RequireAccount() error

RequireAccount validates that an account is configured and is a valid numeric ID. Returns an error if no account ID is set or if it contains non-digit characters. Commands that perform account-scoped operations should call this before using Account().

Note: ForAccount() panics on invalid account IDs, so this validation must match exactly - only ASCII digits 0-9 are allowed (no signs, spaces, etc.).

func (*App) Resolve

func (a *App) Resolve() *resolve.Resolver

Resolve returns a Resolver for interactive prompts when CLI options are missing. The resolver uses the app's SDK, auth manager, and config to fetch available options and prompt the user to select interactively.

Usage:

accountID, err := app.Resolve().Account(ctx)
if err != nil {
    return err
}

type GlobalFlags

type GlobalFlags struct {
	// Output format flags
	JSON    bool
	Quiet   bool
	MD      bool // Literal Markdown syntax output
	Styled  bool // Force ANSI styled output (even when piped)
	IDsOnly bool
	Count   bool
	Agent   bool

	// Context flags
	Project  string
	Account  string
	Todolist string
	Profile  string // Named profile

	// Behavior flags
	Verbose  int // 0=off, 1=operations, 2=operations+requests (stacks with -v -v or -vv)
	Stats    bool
	NoStats  bool // Explicit disable (overrides --stats and dev default)
	Hints    bool
	NoHints  bool // Explicit disable (overrides --hints and dev default)
	CacheDir string
}

GlobalFlags holds values for global CLI flags.

Jump to

Keyboard shortcuts

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