config

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultBundesland = "Baden-Württemberg"

DefaultBundesland is the default German federal state for holidays.

Variables

This section is empty.

Functions

func DefaultConfigPath

func DefaultConfigPath() (string, error)

DefaultConfigPath returns the path to the global config file. Uses $XDG_CONFIG_HOME/odoo-work-cli/config.toml if set, otherwise ~/.config/odoo-work-cli/config.toml.

func DefaultConfigTemplate added in v0.2.0

func DefaultConfigTemplate() []byte

DefaultConfigTemplate returns the embedded default configuration template.

func InstallConfig added in v0.2.0

func InstallConfig(path string) error

InstallConfig writes the default configuration template to the given path. Returns an error if the file already exists. Creates parent directories as needed.

func WalkConfigFiles

func WalkConfigFiles(startDir string) ([]string, error)

WalkConfigFiles walks from startDir upward to the filesystem root, collecting .odoo-work-cli.toml files. Returns paths ordered root-most first (merge order: root-most has lowest priority).

Types

type Config

type Config struct {
	URL           string                 `toml:"url"`
	Database      string                 `toml:"database"`
	Username      string                 `toml:"username"`
	Password      string                 `toml:"-"`
	WebPassword   string                 `toml:"-"`
	TOTPSecret    string                 `toml:"-"`
	OPSecrets     *OPSecrets             `toml:"op_secrets"`
	Models        map[string]ModelConfig `toml:"models"`
	Hours         HoursLimits            `toml:"hours"`
	Keys          KeysConfig             `toml:"keys"`
	Bundesland    string                 `toml:"bundesland"`     // German federal state for holidays (e.g. "Bayern")
	CompanyColors map[string]string      `toml:"company_colors"` // company name → lipgloss color string
}

Config holds the application configuration.

func LoadFromEnv

func LoadFromEnv() *Config

LoadFromEnv reads configuration from environment variables. It reads whatever env vars are set without requiring any. Use Validate to check that all required fields are present.

func LoadFromTOML

func LoadFromTOML(path string) (*Config, error)

LoadFromTOML reads configuration from a TOML file. Returns an error if the file contains a password key — passwords must come from environment variables only, never from config files.

func (*Config) ApplyDefaults

func (c *Config) ApplyDefaults()

ApplyDefaults fills in zero-valued fields with defaults.

func (*Config) Merge

func (c *Config) Merge(other *Config)

Merge overlays values from other onto c. Non-empty fields in other take precedence. Model configs from other are merged key-by-key, with overlay models replacing base models of the same name.

func (*Config) OdooDatabase

func (c *Config) OdooDatabase() string

func (*Config) OdooPassword

func (c *Config) OdooPassword() string

func (*Config) OdooURL

func (c *Config) OdooURL() string

func (*Config) OdooUsername

func (c *Config) OdooUsername() string

func (*Config) OdooWebPassword added in v0.4.0

func (c *Config) OdooWebPassword() string

func (*Config) Validate

func (c *Config) Validate() error

Validate checks that all required configuration fields are set. Returns an error listing missing fields.

type ConfigReader

type ConfigReader interface {
	OdooURL() string
	OdooDatabase() string
	OdooUsername() string
	OdooPassword() string
}

ConfigReader provides access to configuration values.

type DiscoverResult

type DiscoverResult struct {
	Files  []string // config files that were loaded, in merge order
	Config *Config
}

DiscoverResult holds the result of configuration discovery.

func Discover

func Discover(configFlag string) (*DiscoverResult, error)

Discover loads configuration using file discovery and environment variables.

If configFlag is non-empty, only that file is loaded (skip discovery). Otherwise: load global config (if exists), walk files (root-most to cwd), then overlay env vars. Env vars always have highest priority.

type ExtraField

type ExtraField struct {
	Name  string `toml:"name"`  // display name (e.g. "product_owner")
	Field string `toml:"field"` // Odoo field name (e.g. "x_studio_productowner")
	Type  string `toml:"type"`  // Odoo type: many2one, char, boolean, integer, float
}

ExtraField describes a custom Odoo field to fetch for a model.

type Filter

type Filter struct {
	Field string `toml:"field"` // Odoo field path (e.g. "company_id.name")
	Op    string `toml:"op"`    // comparison operator (e.g. "=", "!=", "ilike")
	Value string `toml:"value"` // filter value
}

Filter describes a default query filter for a model.

type HoursLimits

type HoursLimits struct {
	DailyLow   float64 `toml:"daily_low"`   // below this: yellow (default 6)
	DailyHigh  float64 `toml:"daily_high"`  // above this: red (default 9)
	WeeklyLow  float64 `toml:"weekly_low"`  // below this: yellow (default 35)
	WeeklyHigh float64 `toml:"weekly_high"` // above this: red (default 40)
}

HoursLimits holds threshold values for hour coloring in the TUI.

func DefaultHoursLimits

func DefaultHoursLimits() HoursLimits

DefaultHoursLimits returns the default work hour thresholds.

type KeysConfig

type KeysConfig map[string][]string

KeysConfig maps action names to key binding strings. Each action maps to one or more key strings (e.g. "q", "ctrl+c").

func (*KeysConfig) UnmarshalTOML

func (kc *KeysConfig) UnmarshalTOML(data interface{}) error

UnmarshalTOML normalizes TOML values: a single string becomes a one-element slice, and an array of strings stays as-is.

type ModelConfig

type ModelConfig struct {
	ExtraFields []ExtraField `toml:"extra_fields"`
	Filters     []Filter     `toml:"filters"`
}

ModelConfig holds per-model configuration.

type OPSecrets added in v0.3.0

type OPSecrets struct {
	URL        string `toml:"url"`
	Database   string `toml:"database"`
	Username   string `toml:"username"`
	APIKey     string `toml:"api-key"`
	Password   string `toml:"password"`
	TOTPSecret string `toml:"totp_secret"`
}

OPSecrets holds 1Password vault references (op:// URIs) for config fields. When present in the config file, these are resolved at runtime via the op CLI.

Jump to

Keyboard shortcuts

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