config

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package config loads, resolves and persists CLI configuration. Values are resolved with the precedence flag > environment > config file > default.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dir

func Dir() (string, error)

Dir returns the OS-appropriate config directory for the CLI (~/.config/api2convert, %AppData%\api2convert, ~/Library/Application Support/api2convert).

func File

func File() (string, error)

File returns the full path to config.toml.

func Save

func Save(c Config) error

Save writes config.toml with 0600 permissions (dir 0700), so a stored API key is never group/other-readable. The write is atomic (temp file + rename) so a crash mid-write can't corrupt an existing config, and the 0600 mode is applied explicitly — O_CREATE alone would leave a pre-existing 0644 file world-readable.

func SaveState added in v1.2.0

func SaveState(s State) error

SaveState writes state.json atomically (temp file + rename) so a crash mid-write can't corrupt an existing file.

func StateFile added in v1.2.0

func StateFile() (string, error)

StateFile returns the full path to state.json.

Types

type Config

type Config struct {
	APIKey      string `toml:"api_key,omitempty"`
	BaseURL     string `toml:"base_url,omitempty"`
	Timeout     string `toml:"timeout,omitempty"`
	PollTimeout string `toml:"poll_timeout,omitempty"`
	MaxRetries  *int   `toml:"max_retries,omitempty"`
	Output      string `toml:"output,omitempty"`
	Concurrency int    `toml:"concurrency,omitempty"`
}

Config is the on-disk configuration (config.toml). Durations are stored as human-editable Go duration strings (e.g. "30s", "5m"). MaxRetries is a pointer so an explicit 0 (disable retries) can be distinguished from "unset".

func Load

func Load() (Config, error)

Load reads config.toml. A missing file is not an error — it returns a zero Config so first-run works without any file present.

type Flags

type Flags struct {
	APIKey      string
	BaseURL     string
	Timeout     string
	PollTimeout string
	MaxRetries  int
	Output      string
	Concurrency int
}

Flags carries the raw CLI flag values used during resolution. Empty strings, -1 (MaxRetries) and 0 (Concurrency) mean "unset".

type Resolved

type Resolved struct {
	APIKey      string
	BaseURL     string
	Timeout     time.Duration
	PollTimeout time.Duration
	MaxRetries  int // -1 means "use SDK default"
	Output      string
	Concurrency int // 0 means "auto"
}

Resolved is the effective configuration after merging all sources.

func Resolve

func Resolve(file Config, fl Flags, getenv func(string) string) (Resolved, error)

Resolve merges a file Config, CLI Flags and the environment into the effective Resolved settings. It returns an error for invalid user input (bad duration, non-integer retries, unknown output mode) rather than silently ignoring it.

type State added in v1.2.0

type State struct {
	// LastUpdateCheck is when the background "newer release?" check last ran. A
	// zero value means it has never run.
	LastUpdateCheck time.Time `json:"last_update_check,omitempty"`
}

State is machine-managed CLI state, kept separate from the user-edited config.toml so a routine write (e.g. the update-check timestamp) never touches the API-key-bearing config file. It lives beside it as state.json.

func LoadState added in v1.2.0

func LoadState() (State, error)

LoadState reads state.json. A missing file is not an error — it returns a zero State so first-run works without any file present.

Jump to

Keyboard shortcuts

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