Skip to content

Commit 12c0c42

Browse files
authored
feat: correctly use the xdg library, which has the side effect to fix the config survey (#2195)
1 parent 3ed38d8 commit 12c0c42

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

cmd/root.go

+12-14
Original file line numberDiff line numberDiff line change
@@ -107,24 +107,22 @@ func Execute(ctx context.Context, version string) {
107107
}
108108
}
109109

110-
// Return locations where Act's config can be found in order : XDG spec, .actrc in HOME directory, .actrc in invocation directory
110+
// Return locations where Act's config can be found in order: XDG spec, .actrc in HOME directory, .actrc in invocation directory
111111
func configLocations() []string {
112112
configFileName := ".actrc"
113113

114-
// reference: https://specifications.freedesktop.org/basedir-spec/latest/ar01s03.html
115-
var actrcXdg string
116-
for _, fileName := range []string{"act/actrc", configFileName} {
117-
if foundConfig, err := xdg.SearchConfigFile(fileName); foundConfig != "" && err == nil {
118-
actrcXdg = foundConfig
119-
break
120-
}
121-
}
114+
homePath := filepath.Join(UserHomeDir, configFileName)
115+
invocationPath := filepath.Join(".", configFileName)
122116

123-
return []string{
124-
actrcXdg,
125-
filepath.Join(UserHomeDir, configFileName),
126-
filepath.Join(".", configFileName),
117+
// Though named xdg, adrg's lib support macOS and Windows config paths as well
118+
// It also takes cares of creating the parent folder so we don't need to bother later
119+
specPath, err := xdg.ConfigFile("act/actrc")
120+
if err != nil {
121+
specPath = homePath
127122
}
123+
124+
// This order should be enforced since the survey part relies on it
125+
return []string{specPath, homePath, invocationPath}
128126
}
129127

130128
var commonSocketPaths = []string{
@@ -554,7 +552,7 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
554552
}
555553
}
556554
if !cfgFound && len(cfgLocations) > 0 {
557-
// The first config location refers to the XDG spec one
555+
// The first config location refers to the global config folder one
558556
if err := defaultImageSurvey(cfgLocations[0]); err != nil {
559557
log.Fatal(err)
560558
}

0 commit comments

Comments
 (0)