on main help sign in
fix: prevent nil ptr
ac782d1Carlos Alexandro Becker
go.mod+2−1
@@ -42,11 +42,12 @@ require (
42 github.com/tidwall/sjson v1.2.5
42 github.com/tidwall/sjson v1.2.5
43 github.com/u-root/u-root v0.14.1-0.20250722142936-bf4e78a90dfc
43 github.com/u-root/u-root v0.14.1-0.20250722142936-bf4e78a90dfc
44 github.com/zeebo/xxh3 v1.0.2
44 github.com/zeebo/xxh3 v1.0.2
45− golang.org/x/exp v0.0.0-20250305212735-054e65f0b394
46 gopkg.in/natefinch/lumberjack.v2 v2.2.1
45 gopkg.in/natefinch/lumberjack.v2 v2.2.1
47 mvdan.cc/sh/v3 v3.11.0
46 mvdan.cc/sh/v3 v3.11.0
48)
47)
49
48
49+require golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 // indirect
50+
50require (
51require (
51 cloud.google.com/go v0.116.0 // indirect
52 cloud.google.com/go v0.116.0 // indirect
52 cloud.google.com/go/auth v0.13.0 // indirect
53 cloud.google.com/go/auth v0.13.0 // indirect
internal/config/config.go+1−1
@@ -3,6 +3,7 @@ package config
3import (
3import (
4 "context"
4 "context"
5 "fmt"
5 "fmt"
6+ "log/slog"
6 "net/http"
7 "net/http"
7 "os"
8 "os"
8 "slices"
9 "slices"
@@ -13,7 +14,6 @@ import (
13 "github.com/charmbracelet/crush/internal/csync"
14 "github.com/charmbracelet/crush/internal/csync"
14 "github.com/charmbracelet/crush/internal/env"
15 "github.com/charmbracelet/crush/internal/env"
15 "github.com/tidwall/sjson"
16 "github.com/tidwall/sjson"
16− "golang.org/x/exp/slog"
17)
17)
18
18
19const (
19const (
internal/config/init.go+10−9
@@ -6,12 +6,9 @@ import (
6 "path/filepath"
6 "path/filepath"
7 "strings"
7 "strings"
8 "sync"
8 "sync"
9− "sync/atomic"
10)
9)
11
10
12−const (
13− InitFlagFilename = "init"
11+const InitFlagFilename = "init"
14−)
15
12
16type ProjectInitFlag struct {
13type ProjectInitFlag struct {
17 Initialized bool `json:"initialized"`
14 Initialized bool `json:"initialized"`
@@ -19,25 +16,29 @@ type ProjectInitFlag struct {
19
16
20// TODO: we need to remove the global config instance keeping it now just until everything is migrated
17// TODO: we need to remove the global config instance keeping it now just until everything is migrated
21var (
18var (
22− instance atomic.Pointer[Config]
19+ instance *Config
23 cwd string
20 cwd string
24− once sync.Once // Ensures the initialization happens only once
21+ once sync.Once
22+ wg sync.WaitGroup
25)
23)
26
24
27func Init(workingDir string, debug bool) (*Config, error) {
25func Init(workingDir string, debug bool) (*Config, error) {
28 var err error
26 var err error
27+ wg.Add(1)
29 once.Do(func() {
28 once.Do(func() {
30 cwd = workingDir
29 cwd = workingDir
31 var cfg *Config
30 var cfg *Config
32 cfg, err = Load(cwd, debug)
31 cfg, err = Load(cwd, debug)
33− instance.Store(cfg)
32+ instance = cfg
33+ wg.Done()
34 })
34 })
35
35
36− return instance.Load(), err
36+ return instance, err
37}
37}
38
38
39func Get() *Config {
39func Get() *Config {
40− return instance.Load()
40+ wg.Wait()
41+ return instance
41}
42}
42
43
43func ProjectNeedsInitialization() (bool, error) {
44func ProjectNeedsInitialization() (bool, error) {