switch from $HOME to UserConfigDir

This commit is contained in:
Stephan Hradek 2023-09-07 17:35:06 +02:00 committed by Manuel Rüger
parent 295d17e6f3
commit de50b62875

14
main.go
View File

@ -125,7 +125,7 @@ var flags = []cli.Flag{
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
Value: filepath.Join(os.Getenv("HOME"), ".config/mark"),
Value: configFilePath(),
Usage: "use the specified configuration file.",
TakesFile: true,
EnvVars: []string{"MARK_CONFIG"},
@ -182,11 +182,11 @@ func main() {
return altsrc.NewTomlSourceFromFile(filePath)
} else {
// Fall back to default if config is unset and path exists
_, err := os.Stat(filepath.Join(os.Getenv("HOME"), ".config/mark"))
_, err := os.Stat(configFilePath())
if os.IsNotExist(err) {
return &altsrc.MapInputSource{}, nil
}
return altsrc.NewTomlSourceFromFile(filepath.Join(os.Getenv("HOME"), ".config/mark"))
return altsrc.NewTomlSourceFromFile(configFilePath())
}
}),
EnableBashCompletion: true,
@ -515,3 +515,11 @@ func processFile(
return target
}
func configFilePath() string {
fp, err := os.UserConfigDir()
if err != nil {
log.Fatal(err)
}
return filepath.Join(fp, "mark")
}