@@ -5,7 +5,6 @@ import (
6 "encoding/json"
6 "encoding/json"
@@ -25,25 +24,11 @@ import (
25 "github.com/charmbracelet/crush/internal/home"
24 "github.com/charmbracelet/crush/internal/home"
26 "github.com/charmbracelet/crush/internal/log"
25 "github.com/charmbracelet/crush/internal/log"
27 powernapConfig "github.com/charmbracelet/x/powernap/pkg/config"
26 powernapConfig "github.com/charmbracelet/x/powernap/pkg/config"
27+ "github.com/qjebbs/go-jsons"
30const defaultCatwalkURL = "https://catwalk.charm.sh"
30const defaultCatwalkURL = "https://catwalk.charm.sh"
32−// LoadReader config via io.Reader.
33−func LoadReader(fd io.Reader) (*Config, error) {
34− data, err := io.ReadAll(fd)
40− err = json.Unmarshal(data, &config)
47// Load loads the configuration from the default paths.
32// Load loads the configuration from the default paths.
48func Load(workingDir, dataDir string, debug bool) (*Config, error) {
33func Load(workingDir, dataDir string, debug bool) (*Config, error) {
49 configPaths := lookupConfigs(workingDir)
34 configPaths := lookupConfigs(workingDir)
@@ -632,35 +617,39 @@ func lookupConfigs(cwd string) []string {
634func loadFromConfigPaths(configPaths []string) (*Config, error) {
619func loadFromConfigPaths(configPaths []string) (*Config, error) {
635− var configs []io.Reader
620+ var configs [][]byte
637 for _, path := range configPaths {
622 for _, path := range configPaths {
638− fd, err := os.Open(path)
623+ data, err := os.ReadFile(path)
639 if err != nil {
624 if err != nil {
640 if os.IsNotExist(err) {
625 if os.IsNotExist(err) {
643 return nil, fmt.Errorf("failed to open config file %s: %w", path, err)
628 return nil, fmt.Errorf("failed to open config file %s: %w", path, err)
645− defer fd.Close()
630+ if len(data) == 0 {
647− configs = append(configs, fd)
633+ configs = append(configs, data)
650− return loadFromReaders(configs)
636+ return loadFromBytes(configs)
653−func loadFromReaders(readers []io.Reader) (*Config, error) {
639+func loadFromBytes(configs [][]byte) (*Config, error) {
654− if len(readers) == 0 {
640+ if len(configs) == 0 {
655 return &Config{}, nil
641 return &Config{}, nil
658− merged, err := Merge(readers)
644+ data, err := jsons.Merge(configs)
659 if err != nil {
645 if err != nil {
660− return nil, fmt.Errorf("failed to merge configuration readers: %w", err)
646+ return nil, err
662−
648+ var config Config
663− return LoadReader(merged)
649+ if err := json.Unmarshal(data, &config); err != nil {
666func hasVertexCredentials(env env.Env) bool {
655func hasVertexCredentials(env env.Env) bool {