Documentation
¶
Overview ¶
Package appctx provides application context helpers.
Index ¶
- func WithApp(ctx context.Context, app *App) context.Context
- type App
- func (a *App) Account() *basecamp.AccountClient
- func (a *App) ApplyFlags()
- func (a *App) Err(err error) error
- func (a *App) IsInteractive() bool
- func (a *App) IsMachineOutput() bool
- func (a *App) OK(data any, opts ...output.ResponseOption) error
- func (a *App) RequireAccount() error
- func (a *App) Resolve() *resolve.Resolver
- type GlobalFlags
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
FromContext retrieves the app from the context.
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 ¶
Err outputs an error response, including stats in the envelope for JSON/Markdown or printing to stderr for styled output.
func (*App) IsInteractive ¶
IsInteractive returns true if the terminal supports interactive TUI.
func (*App) IsMachineOutput ¶
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 ¶
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 ¶
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.