config

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package config resolves aptbase settings from layered sources.

Resolution order, where a later layer overrides an earlier one (last wins):

built-in defaults
  → /etc/aptbase.ini
  → ~/aptbase.ini
  → APTBASE_* environment variables
  → command-line flags (only when explicitly set)

When --config (or APTBASE_CONFIG) names an explicit file, only that file is read instead of the two well-known locations.

Index

Constants

View Source
const (
	KeyAPI           = "api"
	KeyServer        = "server"
	KeyUser          = "user"
	KeyPassword      = "password"
	KeyDistributions = "distributions"
	KeyRepos         = "repos"
	KeyPrefix        = "prefix"
	KeyInsecure      = "insecure"
	KeyTimeout       = "timeout"
	KeyJSON          = "json"
	KeyNoColor       = "no-color"
	KeyYes           = "yes"
	KeyDebug         = "debug"
)

Setting keys. These double as INI keys and CLI flag names.

View Source
const DefaultTemplate = `` /* 1346-byte string literal not displayed */

DefaultTemplate is the annotated config.ini written by `aptbase config new`.

View Source
const SystemConfigPath = "/etc/aptbase.ini"

SystemConfigPath is the default system-wide config location.

Variables

This section is empty.

Functions

func Render

func Render(s *Settings) string

Render produces a config.ini reflecting the resolved settings (config file + env + flags combined). It is written by `aptbase config print` so the current effective configuration can be captured and piped to a file. The output is plain text with no color, suitable for redirection.

func WriteDefault

func WriteDefault(path string, force bool) error

WriteDefault writes the annotated default template to path. It refuses to overwrite an existing file unless force is true, creating parent directories as needed.

Types

type Settings

type Settings struct {
	APIs          []string
	Server        string
	User          string
	Password      string
	HasPassword   bool // whether a password was supplied (vs. prompt-on-401)
	Distributions []string
	Repos         []string
	Prefix        string
	Insecure      bool
	Timeout       time.Duration
	JSON          bool
	NoColor       bool
	Yes           bool
	Debug         bool
	// contains filtered or unexported fields
}

Settings holds the fully resolved configuration for a single invocation.

func Defaults

func Defaults() *Settings

Defaults returns the built-in default settings (the base layer before any config file, environment, or flag is applied).

func Resolve

func Resolve(flags *pflag.FlagSet) (*Settings, error)

Resolve builds Settings from all layers. flags is the root command's persistent flag set; only flags reported as Changed are applied.

func (*Settings) Source

func (s *Settings) Source(key string) string

Source returns where the value for key was resolved from (e.g. "flag", "/etc/aptbase.ini", "env:APTBASE_API", "default").

Jump to

Keyboard shortcuts

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