persist

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigDirName = "goenv"
View Source
const ThemeDefault = "default"

ThemeDefault is the default theme name.

Variables

This section is empty.

Functions

func AtomicWriteFile

func AtomicWriteFile(path string, data []byte, perm os.FileMode) error

AtomicWriteFile writes data to a file atomically by writing to a temp file and renaming (atomic on POSIX).

func ClearHistory

func ClearHistory() error

ClearHistory removes the history file.

func DefaultSnapshotDir

func DefaultSnapshotDir() (string, error)

DefaultSnapshotDir returns the default directory for snapshots.

func ExportSnapshot

func ExportSnapshot(snapshot Snapshot, filePath string) error

ExportSnapshot saves a snapshot to a JSON file.

func PresetsDir

func PresetsDir() (string, error)

PresetsDir returns the directory for storing presets.

func SanitizeFilename

func SanitizeFilename(name string) string

SanitizeFilename removes or replaces invalid filename characters.

func SaveConfig

func SaveConfig(cfg Config) error

SaveConfig persists configuration to disk.

func SaveHistory

func SaveHistory(history SessionHistory, maxEntries int) error

SaveHistory persists history to disk. maxEntries controls the maximum number of history records to keep. If maxEntries <= 0, the default of 50 is used.

func SortModeToString

func SortModeToString(mode SortMode) string

SortModeToString converts a SortMode to string.

func UniqueFilePath

func UniqueFilePath(dir, base, ext string) string

UniqueFilePath returns a file path that doesn't collide with existing files. If dir/base.ext exists, it tries dir/base_2.ext, dir/base_3.ext, etc.

Types

type Config

type Config struct {
	SortMode      string   `json:"sortMode"`
	Theme         string   `json:"theme,omitempty"`
	Favorites     []string `json:"favorites,omitzero"`
	WatchInterval int      `json:"watchInterval,omitempty"`
	MaxHistory    int      `json:"maxHistory,omitempty"`
}

Config holds user preferences that persist across sessions.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default configuration.

func LoadConfig

func LoadConfig() (Config, error)

LoadConfig loads configuration from disk. Returns default config if file doesn't exist.

type EditRecord

type EditRecord struct {
	Key      string `json:"key"`
	OldValue string `json:"oldValue"`
	NewValue string `json:"newValue"`
}

EditRecord stores a single edit operation for undo/redo functionality.

type Preset

type Preset struct {
	Snapshot
	BuiltIn bool
}

Preset represents a named environment configuration.

func BuiltinPresets

func BuiltinPresets() []Preset

BuiltinPresets returns the set of built-in starter presets. These are shipped with goenv and cannot be deleted by the user.

func ListPresets

func ListPresets() (presets []Preset, skipped int, err error)

ListPresets returns all saved presets. Also returns the count of files that could not be parsed.

type SessionHistory

type SessionHistory struct {
	Records    []EditRecord `json:"records"`
	CurrentIdx int          `json:"currentIdx"`
}

SessionHistory stores edit history that persists across sessions.

func LoadHistory

func LoadHistory() (SessionHistory, error)

LoadHistory loads history from disk. Returns empty history if file doesn't exist.

type Snapshot

type Snapshot struct {
	Name        string            `json:"name"`
	Description string            `json:"description,omitempty"`
	CreatedAt   time.Time         `json:"createdAt"`
	GoVersion   string            `json:"goVersion,omitempty"`
	Variables   map[string]string `json:"variables"`
}

Snapshot represents a saved state of Go environment variables.

func ImportSnapshot

func ImportSnapshot(filePath string) (Snapshot, error)

ImportSnapshot loads a snapshot from a JSON file.

func ListSnapshots

func ListSnapshots() (snapshots []Snapshot, skipped int, err error)

ListSnapshots returns all snapshots in the default directory. Also returns the count of files that could not be parsed.

func NewSnapshot

func NewSnapshot(name string, items []goenv.EnvVar, goVersion string) Snapshot

NewSnapshot creates a new snapshot from the given environment variables.

type SnapshotDiff

type SnapshotDiff struct {
	Added    map[string]string // In snapshot but not current
	Removed  map[string]string // In current but not snapshot
	Modified map[string]struct {
		Current  string
		Snapshot string
	}
	Unchanged []string
}

SnapshotDiff represents the difference between current env and a snapshot.

func CompareWithSnapshot

func CompareWithSnapshot(items []goenv.EnvVar, snapshot Snapshot) SnapshotDiff

CompareWithSnapshot compares current environment with a snapshot.

type SortMode

type SortMode int

SortMode determines how environment variables are sorted in the list.

const (
	SortAlpha         SortMode = iota // Alphabetical by key
	SortModifiedFirst                 // Modified variables first, then alphabetical
	SortCategory                      // Grouped by category, then alphabetical
)

Sort mode options.

func SortModeFromString

func SortModeFromString(s string) SortMode

SortModeFromString converts a string to SortMode.

func (SortMode) Next

func (s SortMode) Next() SortMode

Next returns the next sort mode in the cycle.

func (SortMode) String

func (s SortMode) String() string

String returns a human-readable name for the sort mode.

Jump to

Keyboard shortcuts

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