feat: correctly use the xdg library, which has the side effect to fix the config survey (#2195)

This commit is contained in:
Milo Moisson 2024-02-01 22:57:16 +01:00 committed by GitHub
parent 3ed38d8e8b
commit 12c0c4277a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 14 deletions

View File

@ -111,20 +111,18 @@ func Execute(ctx context.Context, version string) {
func configLocations() []string { func configLocations() []string {
configFileName := ".actrc" configFileName := ".actrc"
// reference: https://specifications.freedesktop.org/basedir-spec/latest/ar01s03.html homePath := filepath.Join(UserHomeDir, configFileName)
var actrcXdg string invocationPath := filepath.Join(".", configFileName)
for _, fileName := range []string{"act/actrc", configFileName} {
if foundConfig, err := xdg.SearchConfigFile(fileName); foundConfig != "" && err == nil { // Though named xdg, adrg's lib support macOS and Windows config paths as well
actrcXdg = foundConfig // It also takes cares of creating the parent folder so we don't need to bother later
break specPath, err := xdg.ConfigFile("act/actrc")
} if err != nil {
specPath = homePath
} }
return []string{ // This order should be enforced since the survey part relies on it
actrcXdg, return []string{specPath, homePath, invocationPath}
filepath.Join(UserHomeDir, configFileName),
filepath.Join(".", configFileName),
}
} }
var commonSocketPaths = []string{ var commonSocketPaths = []string{
@ -554,7 +552,7 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
} }
} }
if !cfgFound && len(cfgLocations) > 0 { 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 { if err := defaultImageSurvey(cfgLocations[0]); err != nil {
log.Fatal(err) log.Fatal(err)
} }