Skip to content

Commit fcdd652

Browse files
committed
start: Refactor Config loading
Config loading needs to behave in different ways than other commands like xdg-open and run. Move it inside the start package instead. Signed-off-by: Paulo Gomes <[email protected]>
1 parent 29b88ea commit fcdd652

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

cmd/cli/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func profileConfigOrDefault(profile string) *types.Config {
8787
// Try to load the profile specific config.
8888
path := files.ProfileConfig(profile)
8989
target, err := os.Readlink(path)
90+
slog.Debug("try to load profile config", "profile", profile, "path", path, target, "target")
9091

9192
if err == nil {
9293
c := config(target)

cmd/cli/start.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ qubesome start -git https://github.com/qubesome/sample-dotfiles i3
4747
},
4848
},
4949
Action: func(ctx context.Context, cmd *cli.Command) error {
50-
cfg := profileConfigOrDefault(targetProfile)
51-
5250
return profiles.Run(
53-
profiles.WithConfig(cfg),
5451
profiles.WithProfile(targetProfile),
5552
profiles.WithGitURL(gitURL),
5653
profiles.WithPath(path),

internal/profiles/options.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package profiles
22

33
import (
44
"github.com/qubesome/cli/internal/command"
5-
"github.com/qubesome/cli/internal/types"
65
)
76

87
type Options struct {
@@ -11,7 +10,6 @@ type Options struct {
1110
Local string
1211
Profile string
1312
Runner string
14-
Config *types.Config
1513
}
1614

1715
func WithGitURL(gitURL string) command.Option[Options] {
@@ -37,11 +35,6 @@ func WithProfile(profile string) command.Option[Options] {
3735
o.Profile = profile
3836
}
3937
}
40-
func WithConfig(config *types.Config) command.Option[Options] {
41-
return func(o *Options) {
42-
o.Config = config
43-
}
44-
}
4538

4639
func WithRunner(runner string) command.Option[Options] {
4740
return func(o *Options) {

internal/profiles/profiles.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,25 @@ func Run(opts ...command.Option[Options]) error {
4545
return StartFromGit(o.Runner, o.Profile, o.GitURL, o.Path, o.Local)
4646
}
4747

48-
if o.Config == nil {
48+
path := filepath.Join(o.Local, o.Path, "qubesome.config")
49+
if _, err := os.Stat(path); err != nil {
50+
return err
51+
}
52+
cfg, err := types.LoadConfig(path)
53+
if err != nil {
54+
return err
55+
}
56+
cfg.RootDir = filepath.Dir(path)
57+
58+
if cfg == nil {
4959
return fmt.Errorf("cannot start profile: nil config")
5060
}
51-
profile, ok := o.Config.Profile(o.Profile)
61+
profile, ok := cfg.Profile(o.Profile)
5262
if !ok {
5363
return fmt.Errorf("cannot start profile: profile %q not found", o.Profile)
5464
}
5565

56-
return Start(o.Runner, profile, o.Config)
66+
return Start(o.Runner, profile, cfg)
5767
}
5868

5969
func validGitDir(path string) bool {

0 commit comments

Comments
 (0)