config

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package config handles loading, saving, and defining the application's configuration.

Index

Constants

This section is empty.

Variables

View Source
var ErrConfigNotFound = errors.New("configuration file not found")

ErrConfigNotFound is returned by LoadConfig when no config file is found.

Functions

func SaveConfig

func SaveConfig(cfg Config, customPath string) (string, error)

SaveConfig saves the provided configuration to the specified path or the default location. It creates the necessary directories if they don't exist. It returns the path where the file was saved and any error encountered.

Types

type Config

type Config struct {
	AgeDays            int      `toml:"age_days"`
	PrimaryMainBranch  string   `toml:"primary_main_branch"`
	ProtectedBranches  []string `toml:"protected_branches"`
	LastVersionCheck   int64    `toml:"last_version_check"`   // Unix timestamp of last check
	LatestKnownVersion string   `toml:"latest_known_version"` // Latest version found during checks

	// Internal map for faster lookups, not loaded from TOML directly
	ProtectedBranchMap map[string]bool `toml:"-"`
}

Config holds the application configuration settings. Tags correspond to the keys in the TOML configuration file.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config struct with default values.

func FirstRunSetup

func FirstRunSetup(reader *bufio.Reader, writer io.Writer) (Config, error)

FirstRunSetup prompts the user for initial configuration values when no config file is found. It takes an input reader and output writer for flexibility (e.g., testing). It returns the generated Config struct based on user input or defaults.

func LoadConfig

func LoadConfig(customPath string) (Config, error)

LoadConfig loads configuration from the specified path or the default location. If a custom path is provided and exists, it's used. Otherwise, it checks the default path. If neither exists, it returns default settings and ErrConfigNotFound. It also populates the ProtectedBranchMap.

Jump to

Keyboard shortcuts

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