Files
iris-context/internal/config/state.go
VERSE 87b91c45d7 feat: update changelog (#131)
closes #130 

- CHANGELOG.md file for people who can view changelog from github
---
`iris changelog` command:
`iris changelog [version]` (e.g. iris changelog v0.5.1)
`iris changelog -n 3` (see changelog of 3 latest releaseas)

=> `iris changelog` looks just like CHANGELOG.md, grouped headers and
all. It only stops looking that way if we personally overwrite that
release's description with something else
=> With 1-hour local cache (invalidated on updater-channel change),
`--refresh` flag to bypass, graceful fallback to stale cache on GitHub
rate-limiting

---
- New auto update config
```toml
# 0 = off (default, notify only), 1 = auto-install, 2 = always confirm first
auto-update = 1
```

- New just debug-changelog and just debug-autoupdate recipes (fully
offline, mocked HTTP servers, no real network/config touched)
2026-08-07 17:16:18 +07:00

73 lines
1.2 KiB
Go

package config
import (
"os"
"path/filepath"
"time"
"github.com/BurntSushi/toml"
)
type UpdaterState struct {
LastCheckTime time.Time `toml:"last-check-time"`
SeenVersion string `toml:"seen-version"`
// auto-update escalation ladder state, see decideAutoUpdateAction
AutoUpdateTarget string `toml:"auto-update-target"`
AutoUpdateAttempt int `toml:"auto-update-attempt"`
DeclinedVersion string `toml:"declined-version"`
}
type State struct {
LastMode string `toml:"last-mode"`
Updater UpdaterState `toml:"updater"`
}
func LoadState() *State {
s := DefaultState()
path, err := StatePath()
if err != nil {
return s
}
if _, statErr := os.Stat(path); os.IsNotExist(statErr) {
return s
}
data, err := os.ReadFile(path)
if err != nil {
return s
}
if _, err := toml.Decode(string(data), s); err != nil {
return s
}
return s
}
func SaveState(s *State) error {
path, err := StatePath()
if err != nil {
return err
}
err = os.MkdirAll(filepath.Dir(path), 0755)
if err != nil {
return err
}
file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
return err
}
defer file.Close()
enc := toml.NewEncoder(file)
if err := enc.Encode(s); err != nil {
return err
}
return nil
}