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) Commit() string
- func (a *App) Config() *Config
- func (a *App) Date() string
- func (a *App) Execute(ctx context.Context, args []string) error
- func (a *App) Logger() *zerolog.Logger
- func (a *App) NewAuthCommand() *cobra.Command
- func (a *App) NewDepsCommand() *cobra.Command
- func (a *App) NewEmbedCommand() *cobra.Command
- func (a *App) NewFetchCommand() *cobra.Command
- func (a *App) NewGenerateCommand() *cobra.Command
- func (a *App) NewInstallCommand() *cobra.Command
- func (a *App) NewListCommand() *cobra.Command
- func (a *App) NewManCommand() *cobra.Command
- func (a *App) NewServeCommand() *cobra.Command
- func (a *App) NewUninstallCommand() *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) Shutdown(ctx context.Context) error
- func (a *App) Starmap(opts ...starmap.Option) (starmap.Client, error)
- func (a *App) Version() string
- type Config
- 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 a deep copy of the current catalog from the starmap instance. This is a convenience method that handles the starmap initialization and catalog retrieval in one call.
Thread Safety: This method is thread-safe because sm.Catalog() acquires a read lock and returns a deep copy (see starmap.go:71-76). Each caller receives an independent catalog instance with no shared mutable state.
Performance: ~350-400ns per call with 9-10 allocations (single copy).
Per docs/ARCHITECTURE.md § Thread Safety section, this ALWAYS returns a deep copy (provided by sm.Catalog()).
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) NewAuthCommand ¶ added in v0.0.17
NewAuthCommand returns a new auth command with app dependencies.
func (*App) NewDepsCommand ¶ added in v0.0.17
NewDepsCommand returns a new deps command with app dependencies.
func (*App) NewEmbedCommand ¶ added in v0.0.17
NewEmbedCommand returns a new embed command with app dependencies.
func (*App) NewFetchCommand ¶ added in v0.0.17
NewFetchCommand returns a new fetch command with app dependencies.
func (*App) NewGenerateCommand ¶ added in v0.0.17
NewGenerateCommand returns a new generate command with app dependencies.
func (*App) NewInstallCommand ¶ added in v0.0.17
NewInstallCommand returns a new install command with app dependencies.
func (*App) NewListCommand ¶ added in v0.0.17
NewListCommand returns a new list command with app dependencies.
func (*App) NewManCommand ¶ added in v0.0.17
NewManCommand returns a new man command.
func (*App) NewServeCommand ¶ added in v0.0.17
NewServeCommand returns a new serve command with app dependencies.
func (*App) NewUninstallCommand ¶ added in v0.0.17
NewUninstallCommand returns a new uninstall command with app dependencies.
func (*App) NewUpdateCommand ¶ added in v0.0.17
NewUpdateCommand returns a new update command with app dependencies.
func (*App) NewValidateCommand ¶ added in v0.0.17
NewValidateCommand returns a new validate command with app dependencies.
func (*App) NewVersionCommand ¶ added in v0.0.17
NewVersionCommand returns a new version command.
func (*App) OutputFormat ¶
OutputFormat returns the configured output format.
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.
func (*App) Starmap ¶
Starmap returns the starmap instance with optional configuration. When called without options, returns the default cached instance (lazy-initialized, thread-safe). When called with options, creates a new instance with custom configuration (no caching).
This consolidates the previous Starmap() and StarmapWithOptions() methods into a single, more idiomatic Go interface following the variadic options pattern.
type Config ¶
type Config struct {
// Global flags
Verbose bool
Quiet bool
NoColor bool
Format string
// Config file
ConfigFile string
// Starmap configuration
LocalPath string
UseEmbeddedCatalog bool
AutoUpdatesEnabled bool
AutoUpdateInterval time.Duration
RemoteServerURL string
RemoteServerAPIKey string
RemoteServerOnly bool
// 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.yaml) 5. Defaults.
func (*Config) UpdateFromFlags ¶
UpdateFromFlags updates config values from parsed command flags. This should be called after cobra parses flags to ensure flag values take precedence over config file and env vars.
type Option ¶
Option is a functional option for configuring the App.
func WithClient ¶
WithClient sets a custom starmap instance (useful for testing).