Files
superwork/tui/internal/cc/profiles.go
T
2026-06-23 05:02:15 +08:00

39 lines
901 B
Go

package cc
import (
"os"
"path/filepath"
"sort"
"strings"
)
// ClaudeProfile represents a Claude settings profile discovered on disk.
type ClaudeProfile struct {
Name string
Path string
}
// ListClaudeProfiles scans dir for *.json files and returns them sorted by Name.
// A missing or unreadable dir returns an empty slice without error.
func ListClaudeProfiles(dir string) ([]ClaudeProfile, error) {
entries, err := os.ReadDir(dir)
if err != nil {
return []ClaudeProfile{}, nil
}
var profiles []ClaudeProfile
for _, e := range entries {
if e.IsDir() || !strings.HasSuffix(e.Name(), ".json") {
continue
}
name := strings.TrimSuffix(e.Name(), ".json")
profiles = append(profiles, ClaudeProfile{
Name: name,
Path: filepath.Join(dir, e.Name()),
})
}
sort.Slice(profiles, func(i, j int) bool {
return profiles[i].Name < profiles[j].Name
})
return profiles, nil
}