Documentation
¶
Overview ¶
Package state provides CLI commands for state management operations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewCommand ¶
NewCommand creates a new state command with all subcommands. The command requires an environment flag (-e) which is used by all subcommands.
Usage:
rootCmd.AddCommand(state.NewCommand(state.Config{
Logger: lggr,
Domain: myDomain,
ViewState: myViewStateFunc,
}))
Types ¶
type Config ¶
type Config struct {
// Logger is the logger to use for command output. Required.
Logger logger.Logger
// Domain is the domain context for the commands. Required.
Domain domain.Domain
// ViewState is the function that generates state from an environment.
// This is domain-specific and must be provided by the user.
ViewState ViewStateFunc
// Deps holds optional dependencies that can be overridden.
// If fields are nil, production defaults are used.
Deps Deps
}
Config holds the configuration for state commands.
type Deps ¶
type Deps struct {
// EnvironmentLoader loads a deployment environment.
// Default: environment.Load
EnvironmentLoader EnvironmentLoaderFunc
// StateLoader loads the previous state from the environment directory.
// Default: envdir.LoadState
StateLoader StateLoaderFunc
// StateSaver saves the generated state.
// Default: envdir.SaveViewState or domain.SaveViewState
StateSaver StateSaverFunc
}
Deps holds the injectable dependencies for state commands. All fields are optional; nil values will use production defaults. Users can override these to provide custom implementations for their domain.
type EnvironmentLoaderFunc ¶
type EnvironmentLoaderFunc func( ctx context.Context, dom domain.Domain, envKey string, opts ...environment.LoadEnvironmentOption, ) (fdeployment.Environment, error)
EnvironmentLoaderFunc loads a deployment environment for the given domain and environment key.
type StateLoaderFunc ¶
type StateLoaderFunc func(envdir domain.EnvDir) (domain.JSONSerializer, error)
StateLoaderFunc loads the previous state from the environment directory. Returns the state as a JSONSerializer, or an error if loading fails. If the state file does not exist, implementations should return empty JSON.
type StateSaverFunc ¶
StateSaverFunc saves the generated state to a file. If outputPath is empty, it should use the default path in the environment directory.
type ViewStateFunc ¶
type ViewStateFunc = fdeployment.ViewStateV2
ViewStateFunc is an alias for deployment.ViewStateV2 for clarity. It generates the current state view from the environment. It takes the environment and optionally the previous state for incremental updates.