Skip to content

Commit

Permalink
feat: correctly use the xdg library, which has the side effect to fix…
Browse files Browse the repository at this point in the history
… the config survey (#2195)
  • Loading branch information
mrnossiom authored Feb 1, 2024
1 parent 3ed38d8 commit 12c0c42
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,22 @@ func Execute(ctx context.Context, version string) {
}
}

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

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

return []string{
actrcXdg,
filepath.Join(UserHomeDir, configFileName),
filepath.Join(".", configFileName),
// Though named xdg, adrg's lib support macOS and Windows config paths as well
// It also takes cares of creating the parent folder so we don't need to bother later
specPath, err := xdg.ConfigFile("act/actrc")
if err != nil {
specPath = homePath
}

// This order should be enforced since the survey part relies on it
return []string{specPath, homePath, invocationPath}
}

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

0 comments on commit 12c0c42

Please sign in to comment.