cliconfig

package
v0.0.0-...-232ca89 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidArgument is returned when a command line argument is invalid
	ErrInvalidArgument = errors.New("invalid argument format")

	// ErrKeyValueRequired is returned when at least one key=value pair is required
	ErrKeyValueRequired = errors.New("at least one key=value pair required")

	// ErrExactlyOneKey is returned when exactly one key is required
	ErrExactlyOneKey = errors.New("exactly one key required")
)
View Source
var (
	// ErrInvalidKey is returned when a config key doesn't exist in the schema
	ErrInvalidKey = errors.New("invalid config key")

	// ErrListNotSupported is returned when attempting to set a list/array field
	ErrListNotSupported = errors.New("setting list fields not supported, edit config file manually")
)

Functions

func Commands

func Commands(manager *Manager) *cli.Command

Commands creates the config command suite with init, set, get, and list subcommands

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager handles configuration file operations

func NewManager

func NewManager(configMsg proto.Message, appName string) *Manager

NewManager creates a new config manager for the given proto message type

func (*Manager) GetValue

func (m *Manager) GetValue(key string) (string, string, error)

GetValue retrieves a config value by dot-notation key (e.g., "server.host") Returns the value and the source (file path or "default")

func (*Manager) GlobalPath

func (m *Manager) GlobalPath() string

GlobalPath returns the global config file path

func (*Manager) ListAll

func (m *Manager) ListAll() (map[string]ValueWithSource, error)

ListAll returns all config values with their sources

func (*Manager) LocalPath

func (m *Manager) LocalPath() string

LocalPath returns the local config file path

func (*Manager) ReadConfig

func (m *Manager) ReadConfig() (proto.Message, error)

ReadConfig reads and merges config from global and local files Returns the merged config, with local taking precedence over global

func (*Manager) SetGlobalPath

func (m *Manager) SetGlobalPath(path string)

SetGlobalPath sets a custom global config path

func (*Manager) SetLocalPath

func (m *Manager) SetLocalPath(path string)

SetLocalPath sets a custom local config path

func (*Manager) SetServiceName

func (m *Manager) SetServiceName(serviceName string)

SetServiceName sets the service name for service-scoped config

func (*Manager) SetValue

func (m *Manager) SetValue(path string, keyValues map[string]string) error

SetValue sets a config value by dot-notation key

func (*Manager) WriteConfig

func (m *Manager) WriteConfig(path string, msg proto.Message) error

WriteConfig writes config to the specified path

type ValueWithSource

type ValueWithSource struct {
	Value  string
	Source string
}

ValueWithSource holds a config value and its source

Jump to

Keyboard shortcuts

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