config

package
v0.29.4-dev-56e4e32 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2025 License: AGPL-3.0 Imports: 7 Imported by: 0

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

View Source
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 ToMap

func ToMap(cmd *cobra.Command) map[string]any

func TraverseCommands

func TraverseCommands(cmd *cobra.Command, path []string, visitor CommandVisitor) map[string]any

TraverseCommands recursively traverses cobra commands and calls the visitor for each, building nested maps for subcommands

Types

type CommandVisitor

type CommandVisitor func(cmd *cobra.Command, path []string) map[string]any

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

func (cm *ConfigurationManager) GetFlagOrigin(cmd *cobra.Command, flag *pflag.Flag) string

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL