config

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package config owns the CLI's persistent configuration. The fields are intentionally empty during foundation bring-up. Concrete settings will land alongside the first feature that needs them. Load/Save are kept so callers (App, future commands) don't move when fields return.

The config directory follows the conventions used by other SafeDep tools (pmg, gryph): a SafeDep-namespaced subdir under the user's platform config location, with explicit env overrides and respect for XDG layouts on every platform.

When log or cache dirs land later, they will need their own resolvers: logs belong under %LOCALAPPDATA% on Windows (per pmg #82), and cache belongs under os.UserCacheDir() on every platform (per gryph). This package owns config only today.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DBPath

func DBPath() (string, error)

DBPath returns the absolute path to the CLI's sqlite database.

func DataDir

func DataDir() (string, error)

DataDir returns the directory where the CLI stores durable state (sqlite DB, future caches that survive across runs). Internal resolution order:

  1. SAFEDEP_DATA_DIR joined with this tool's name.
  2. XDG_DATA_HOME joined with "safedep/cli".
  3. $HOME/.local/share/safedep/cli when that path already exists.
  4. Platform default joined with "safedep/cli": Linux: ~/.local/share, macOS: ~/Library/Application Support, Windows: %LOCALAPPDATA%.

func EnvVar

func EnvVar(key string) string

EnvVar returns the value of the named environment variable, or empty string if unset. Centralises os.Getenv usage per the project lint rule.

func Save

func Save(cfg *Config) error

Save writes cfg to the config file, creating the directory if needed.

Types

type Config

type Config struct {
	Storage StorageConfig `mapstructure:"storage"`
}

Config is the deserialised CLI config file. Add fields here. Load/Save pick them up automatically via viper's mapstructure binding.

func Load

func Load() (*Config, error)

Load reads the config file into a Config. A missing file is not an error: it returns a zero Config so first-run commands behave like a fresh install. Any other read error (permission, malformed) is fatal.

type StorageConfig

type StorageConfig struct {
	// Retention overrides keyed by storage primitive name as a plain
	// string (matches the TOML/env shape on disk). Callers building a
	// storage.CleanupPolicy convert these into storage.PrimitiveName
	// at the boundary; unknown keys are ignored. Zero duration means
	// "no time-based cleanup, only TTL."
	Retention map[string]time.Duration `mapstructure:"retention"`
}

StorageConfig captures persistent-state configuration. Zero value plus DefaultStorageConfig produces a usable config.

func DefaultStorageConfig

func DefaultStorageConfig() StorageConfig

DefaultStorageConfig returns the baseline storage configuration. No per-primitive defaults are set here today: descriptor-level defaults inside internal/storage are authoritative until users opt into an override.

Jump to

Keyboard shortcuts

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