Documentation
¶
Overview ¶
Package app provides the application context and dependency management for the starmap CLI. It follows idiomatic Go patterns for CLI applications by centralizing configuration, dependency injection, and lifecycle management.
Index ¶
- func Context() (context.Context, context.CancelFunc)
- func ContextWithSignals(parent context.Context) (context.Context, context.CancelFunc)
- func ExitOnError(err error)
- func NewLogger(config *Config) zerolog.Logger
- type App
- func (a *App) BuiltBy() string
- func (a *App) Catalog() (*catalogs.Catalog, error)
- func (a *App) CatalogPath() (string, error)
- func (a *App) CatalogState() (starmap.CatalogState, error)
- func (a *App) Commit() string
- func (a *App) Config() *Config
- func (a *App) CredentialResolver() (sources.ProviderCredentialResolver, error)
- func (a *App) Date() string
- func (a *App) Execute(ctx context.Context, args []string) error
- func (a *App) Logger() *zerolog.Logger
- func (a *App) MigrateCatalogWorkspace(ctx context.Context) (workspace.LegacyLayoutMigrationResult, error)
- func (a *App) NewAuthCommand() *cobra.Command
- func (a *App) NewAuthorsCommand() *cobra.Command
- func (a *App) NewCompletionCommand() *cobra.Command
- func (a *App) NewDepsCommand() *cobra.Command
- func (a *App) NewEmbedCommand() *cobra.Command
- func (a *App) NewManCommand() *cobra.Command
- func (a *App) NewMigrateCommand() *cobra.Command
- func (a *App) NewModelsCommand() *cobra.Command
- func (a *App) NewProvidersCommand() *cobra.Command
- func (a *App) NewServeCommand() *cobra.Command
- func (a *App) NewUpdateCommand() *cobra.Command
- func (a *App) NewValidateCommand() *cobra.Command
- func (a *App) NewVersionCommand() *cobra.Command
- func (a *App) OutputFormat() string
- func (a *App) Readiness() (starmap.CatalogReadiness, error)
- func (a *App) Shutdown(ctx context.Context) error
- func (a *App) Starmap(opts ...starmap.Option) (*starmap.Client, error)
- func (a *App) Version() string
- type Config
- type CredentialSourceConfig
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Context ¶
func Context() (context.Context, context.CancelFunc)
Context creates a new context with signal handling for the application. This is a convenience wrapper around ContextWithSignals that uses context.Background() as the parent.
func ContextWithSignals ¶
ContextWithSignals creates a context that is cancelled when the application receives an interrupt or termination signal. This enables graceful shutdown.
func ExitOnError ¶
func ExitOnError(err error)
ExitOnError is a helper that prints an error and exits with status 1. This is meant to be used in main.go for top-level error handling.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App represents the starmap application with all its dependencies. It provides a centralized place for configuration, logging, and the starmap instance, following the dependency injection pattern.
func New ¶
New creates a new App instance with the given version information. The app is initialized with default configuration that can be customized using functional options.
func (*App) Catalog ¶
Catalog returns the current immutable catalog from the starmap instance. This is a convenience method that handles the starmap initialization and catalog retrieval in one call.
Thread Safety: sm.Catalog atomically loads an immutable generation. Collection reads return caller-owned copies behind interfaces that expose no mutation methods.
func (*App) CatalogPath ¶
CatalogPath returns the configured human provider-YAML workspace, or the canonical per-user default when no override is configured.
func (*App) CatalogState ¶
func (a *App) CatalogState() (starmap.CatalogState, error)
CatalogState atomically returns the current catalog and generation identity.
func (*App) CredentialResolver ¶ added in v0.4.0
func (a *App) CredentialResolver() (sources.ProviderCredentialResolver, error)
CredentialResolver returns the process-owned catalog-acquisition resolver. One resolver owns source caching and single-flight refresh for the process.
func (*App) Execute ¶
Execute runs the starmap CLI application with the given arguments. This is the main entry point called from main.go.
func (*App) MigrateCatalogWorkspace ¶
func (a *App) MigrateCatalogWorkspace(ctx context.Context) (workspace.LegacyLayoutMigrationResult, error)
MigrateCatalogWorkspace explicitly relocates the pre-plan generation store from the configured human workspace path into the CLI's machine state root.
func (*App) NewAuthCommand ¶
NewAuthCommand returns a new auth command with app dependencies.
func (*App) NewAuthorsCommand ¶
NewAuthorsCommand returns a new authors command with app dependencies.
func (*App) NewCompletionCommand ¶
NewCompletionCommand returns a new completion command. This overrides Cobra's auto-generated completion command to add install/uninstall subcommands.
func (*App) NewDepsCommand ¶
NewDepsCommand returns a new deps command with app dependencies.
func (*App) NewEmbedCommand ¶
NewEmbedCommand returns a new embed command with app dependencies.
func (*App) NewManCommand ¶
NewManCommand returns a new man command.
func (*App) NewMigrateCommand ¶
NewMigrateCommand returns the explicit local-storage migration command.
func (*App) NewModelsCommand ¶
NewModelsCommand returns a new models command with app dependencies.
func (*App) NewProvidersCommand ¶
NewProvidersCommand returns a new providers command with app dependencies.
func (*App) NewServeCommand ¶
NewServeCommand returns a new serve command with app dependencies.
func (*App) NewUpdateCommand ¶
NewUpdateCommand returns a new update command with app dependencies.
func (*App) NewValidateCommand ¶
NewValidateCommand returns a new validate command with app dependencies.
func (*App) NewVersionCommand ¶
NewVersionCommand returns a new version command.
func (*App) OutputFormat ¶
OutputFormat returns the configured output format.
func (*App) Readiness ¶
func (a *App) Readiness() (starmap.CatalogReadiness, error)
Readiness reports catalog availability and active embedded-bootstrap budgets.
func (*App) Shutdown ¶
Shutdown performs graceful shutdown of the application. It stops any running background tasks and cleans up resources. The context controls the shutdown timeout - shutdown will abort if context is cancelled.
type Config ¶
type Config struct {
// Global flags
Verbose bool
Quiet bool
NoColor bool
Output string
// Config file
ConfigFile string
// Starmap configuration
// CatalogPath is the human-editable provider YAML workspace.
CatalogPath string
EmbeddedBootstrapMaxAge time.Duration
EmbeddedBootstrapMaxSizeBytes int64
RemoteServerURL string
RemoteServerAPIKey string
RemoteServerOnly bool
CredentialSources map[string]map[string]CredentialSourceConfig
// Logging configuration
LogLevel string
LogFormat string
LogOutput string
}
Config holds the application configuration loaded from various sources including config files, environment variables, and .env files.
func LoadConfig ¶
LoadConfig loads configuration from all sources in order of precedence: 1. Command-line flags (handled by cobra) 2. Environment variables 3. .env files 4. Config file (~/.starmap/config.yaml) 5. Defaults.
type CredentialSourceConfig ¶ added in v0.4.0
type CredentialSourceConfig struct {
Reference string `mapstructure:"reference"`
FallbackAmbient bool `mapstructure:"fallback_ambient"`
}
CredentialSourceConfig selects one explicit provider-field source.
type Option ¶
Option is a functional option for configuring the App.
func WithClient ¶
WithClient sets a custom starmap instance (useful for testing).