Documentation
¶
Overview ¶
Package config provides configuration management for the immich-go application. It integrates Viper for configuration file handling, environment variables, and Cobra for CLI flags. The ConfigurationManager handles flag registration, binding, and origin tracking.
Index ¶
- Constants
- func ToMap(cmd *cobra.Command) map[string]any
- func TraverseCommands(cmd *cobra.Command, path []string, visitor CommandVisitor) map[string]any
- type CommandVisitor
- type ConfigurationManager
- func (cm *ConfigurationManager) GetConfigFile() string
- func (cm *ConfigurationManager) GetFlagOrigin(cmd *cobra.Command, flag *pflag.Flag) string
- func (cm *ConfigurationManager) Init(cfgFile string) error
- func (cm *ConfigurationManager) ProcessCommand(cmd *cobra.Command) error
- func (cm *ConfigurationManager) Save(fileName string) error
Constants ¶
const ( // OriginCLI indicates the value came from command line flags OriginCLI = "cli" // OriginEnvironment indicates the value came from environment variables OriginEnvironment = "environment" // OriginConfigFile indicates the value came from a configuration file OriginConfigFile = "config file" // OriginDefault indicates the value is the default OriginDefault = "default" )
Variables ¶
This section is empty.
Functions ¶
func TraverseCommands ¶
TraverseCommands recursively traverses cobra commands and calls the visitor for each, building nested maps for subcommands
Types ¶
type CommandVisitor ¶
CommandVisitor is a function type for visiting commands during traversal
type ConfigurationManager ¶
type ConfigurationManager struct {
// contains filtered or unexported fields
}
ConfigurationManager manages application configuration using Viper and Cobra. It handles flag registration, binding to configuration sources, and tracks the origin of configuration values (CLI, environment, config file, or default).
func New ¶
func New() *ConfigurationManager
New creates a new ConfigurationManager instance. It initializes the Viper instance and internal maps for origins.
func (*ConfigurationManager) GetConfigFile ¶
func (cm *ConfigurationManager) GetConfigFile() string
GetConfigFile returns the name of the configuration file used, if any. Returns empty string if no config file was loaded.
func (*ConfigurationManager) GetFlagOrigin ¶
GetFlagOrigin returns the origin source of a flag's value. Possible origins are: "cli", "environment", "config file", or "default".
func (*ConfigurationManager) Init ¶
func (cm *ConfigurationManager) Init(cfgFile string) error
Init initializes the configuration manager with the specified config file. If cfgFile is empty, it defaults to looking for "immich-go.toml" in the current directory. It sets up environment variable prefix and automatic environment binding.
func (*ConfigurationManager) ProcessCommand ¶
func (cm *ConfigurationManager) ProcessCommand(cmd *cobra.Command) error
ProcessCommand processes the given command and its subcommands. It registers flags, binds them to Viper, applies configuration values, and tracks the origin of each configuration value. This method should be called once per root command.
func (*ConfigurationManager) Save ¶
func (cm *ConfigurationManager) Save(fileName string) error
Save writes the current configuration to the specified file. The file format is determined by the file extension (e.g., .toml, .yaml, .json).