config

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultConfigDir is the default configuration directory
	DefaultConfigDir = filepath.Join(os.Getenv("HOME"), ".config", "cu")
	// ConfigFileName is the name of the config file
	ConfigFileName = "config"
	// ConfigType is the type of the config file
	ConfigType = "yaml"
	// ProjectConfigFileName is the name of the project config file
	ProjectConfigFileName = ".cu.yml"
)

Functions

func Get

func Get(key string) interface{}

Get returns a configuration value

func GetBool

func GetBool(key string) bool

GetBool returns a boolean configuration value

func GetProjectConfigPath

func GetProjectConfigPath() string

GetProjectConfigPath returns the path to the project config file

func GetString

func GetString(key string) string

GetString returns a string configuration value

func HasProjectConfig

func HasProjectConfig() bool

HasProjectConfig returns true if a project config file was found

func Init

func Init(cfgFile string) error

Init initializes the configuration

func InitProjectConfig

func InitProjectConfig() error

InitProjectConfig creates a new project config file in the current directory

func Save

func Save() error

Save writes the global config file. Only values that came from that file or were written through Set are persisted — project .cu.yml values, environment variables and flags are deliberately excluded, so running `cu config set` inside a project can no longer bake that project's settings into the global config.

func SaveProjectConfig

func SaveProjectConfig(settings map[string]interface{}) error

SaveProjectConfig saves configuration to the project config file

func Set

func Set(key string, value interface{})

Set sets a configuration value for this process and stages it for the global config file, so a following Save persists it there.

func TestInitProjectConfig_Unix

func TestInitProjectConfig_Unix(t *testing.T)

Types

type Config

type Config struct {
	DefaultSpace  string            `mapstructure:"default_space"`
	DefaultFolder string            `mapstructure:"default_folder"`
	DefaultList   string            `mapstructure:"default_list"`
	Output        string            `mapstructure:"output"`
	Debug         bool              `mapstructure:"debug"`
	APIToken      string            `mapstructure:"api_token"`
	Workspaces    map[string]string `mapstructure:"workspaces"`
}

Config represents the application configuration

func Load

func Load() (*Config, error)

Load loads the configuration from file

type Provider

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

Provider wraps viper to implement the ConfigProvider interface

func New

func New() *Provider

New creates a new config provider using the global viper instance

func NewWithViper

func NewWithViper(v *viper.Viper) *Provider

NewWithViper creates a new config provider with a specific viper instance

func (*Provider) AllSettings

func (p *Provider) AllSettings() map[string]interface{}

AllSettings returns all settings

func (*Provider) Get

func (p *Provider) Get(key string) interface{}

Get returns a configuration value

func (*Provider) GetBool

func (p *Provider) GetBool(key string) bool

GetBool returns a boolean configuration value

func (*Provider) GetInt

func (p *Provider) GetInt(key string) int

GetInt returns an integer configuration value

func (*Provider) GetProjectConfigPath

func (p *Provider) GetProjectConfigPath() string

GetProjectConfigPath returns the path to the project config file

func (*Provider) GetString

func (p *Provider) GetString(key string) string

GetString returns a string configuration value

func (*Provider) GetStringMap

func (p *Provider) GetStringMap(key string) map[string]interface{}

GetStringMap returns a string map configuration value

func (*Provider) GetStringSlice

func (p *Provider) GetStringSlice(key string) []string

GetStringSlice returns a string slice configuration value

func (*Provider) HasProjectConfig

func (p *Provider) HasProjectConfig() bool

HasProjectConfig returns true if a project config file was found

func (*Provider) InitProjectConfig

func (p *Provider) InitProjectConfig() error

InitProjectConfig creates a new project config file

func (*Provider) IsSet

func (p *Provider) IsSet(key string) bool

IsSet checks if a key exists

func (*Provider) Save

func (p *Provider) Save() error

Save saves the configuration

func (*Provider) Set

func (p *Provider) Set(key string, value interface{})

Set sets a configuration value

Jump to

Keyboard shortcuts

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