refactor: load settings once per run and reuse shared helpers

The application caches the settings snapshot and reloads it only after
an update through the store, so output and prompt helpers no longer
read and parse config.yml and hosts.yml several times per command.
canPrompt and chooser replace the inline prompt-policy checks.

Checks are tallied by one services.Tally, terminal.Plural replaces the
two app copies, refKind.article/noun replace the comment group's own
words, list commands use servicePage, and web URLs are built by
repositoryURL and webURL in browser.go.

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-12 10:57:39 +02:00
1 parent 9ac5b79e9e
commit 29f62da006
42 files changed
+157 -204

No files matched your search

+8
View File
@@ -15,6 +15,7 @@ import (
"path/filepath"
"strings"
"sync"
"sync/atomic"
"time"
"gitea.dev/tea/internal/filelock"
@@ -102,8 +103,14 @@ type Store struct {
Dir string
LegacyPath string
mu sync.Mutex
// generation counts the updates made through the store.
generation atomic.Uint64
}
// Generation changes whenever an update through the store ran, so callers can tell when a
// snapshot they loaded earlier may be stale.
func (s *Store) Generation() uint64 { return s.generation.Load() }
// New selects an explicit directory or the platform configuration directory.
func New(dir string) *Store {
legacy := ""
@@ -328,6 +335,7 @@ func (s *Store) Update(target Target, update func(*Snapshot) error) error {
// Transaction runs a compensating action under the lock if publishing the target file fails.
// It is used to keep credential storage and account metadata consistent.
func (s *Store) Transaction(target Target, update func(*Snapshot) (func() error, error)) error {
defer s.generation.Add(1)
return s.Locked(func(snapshot Snapshot) error {
unpublished := func() ([]byte, error) {
if target == TargetHosts {