config

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config reads and writes the user configuration file and resolves each setting from flag, environment, file, or default in that order.

Index

Constants

View Source
const (
	KeyAccount = "account"
	KeyMailbox = "mailbox"
	KeyOutput  = "output"

	EnvConfigPath = "MAIL_APP_CLI_CONFIG"
	EnvAccount    = "MAIL_APP_CLI_ACCOUNT"
	EnvMailbox    = "MAIL_APP_CLI_MAILBOX"
	EnvOutput     = "MAIL_APP_CLI_OUTPUT"

	SourceFlag    = "flag"
	SourceEnv     = "env"
	SourceConfig  = "config"
	SourceDefault = "default"
)

Variables

This section is empty.

Functions

func Keys

func Keys() []string

Keys lists the settable keys in display order.

func Path

func Path() (string, error)

Path returns the config file location: $MAIL_APP_CLI_CONFIG, else $XDG_CONFIG_HOME/mail-app-cli/config.json, else ~/.config/mail-app-cli/config.json.

func Save

func Save(cfg Config) error

Save writes the config file, creating its directory.

Types

type Config

type Config struct {
	Account string `json:"account,omitempty"`
	Mailbox string `json:"mailbox,omitempty"`
	Output  string `json:"output,omitempty"`
}

Config is the on-disk shape. Empty values are omitted so the file only records what the user set.

func Load

func Load() (Config, error)

Load reads the config file. A missing file is an empty config, not an error.

func (Config) Get

func (c Config) Get(key string) (string, error)

Get returns the value stored for key.

func (*Config) Set

func (c *Config) Set(key, value string) error

Set validates and stores a value. An empty value clears the key.

type Resolved

type Resolved struct {
	Account Value  `json:"account"`
	Mailbox Value  `json:"mailbox"`
	Output  Value  `json:"output"`
	Path    string `json:"path"`
}

Resolved holds every setting after precedence is applied.

func Resolve

func Resolve(flags map[string]string, cfg Config, getenv func(string) string) Resolved

Resolve applies flag > env > config > default for each key. flags holds only the flags the user explicitly set.

func (Resolved) Rows

func (r Resolved) Rows() [][]string

Rows renders the resolved settings as key, value, source triples in key order.

type Value

type Value struct {
	Value  string `json:"value"`
	Source string `json:"source"`
}

Value is a resolved setting with where it came from.

Jump to

Keyboard shortcuts

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