mirror of
https://github.com/kovetskiy/mark.git
synced 2025-04-24 05:42:40 +08:00
switch from $HOME to UserConfigDir
This commit is contained in:
parent
295d17e6f3
commit
de50b62875
14
main.go
14
main.go
@ -125,7 +125,7 @@ var flags = []cli.Flag{
|
|||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "config",
|
Name: "config",
|
||||||
Aliases: []string{"c"},
|
Aliases: []string{"c"},
|
||||||
Value: filepath.Join(os.Getenv("HOME"), ".config/mark"),
|
Value: configFilePath(),
|
||||||
Usage: "use the specified configuration file.",
|
Usage: "use the specified configuration file.",
|
||||||
TakesFile: true,
|
TakesFile: true,
|
||||||
EnvVars: []string{"MARK_CONFIG"},
|
EnvVars: []string{"MARK_CONFIG"},
|
||||||
@ -182,11 +182,11 @@ func main() {
|
|||||||
return altsrc.NewTomlSourceFromFile(filePath)
|
return altsrc.NewTomlSourceFromFile(filePath)
|
||||||
} else {
|
} else {
|
||||||
// Fall back to default if config is unset and path exists
|
// 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) {
|
if os.IsNotExist(err) {
|
||||||
return &altsrc.MapInputSource{}, nil
|
return &altsrc.MapInputSource{}, nil
|
||||||
}
|
}
|
||||||
return altsrc.NewTomlSourceFromFile(filepath.Join(os.Getenv("HOME"), ".config/mark"))
|
return altsrc.NewTomlSourceFromFile(configFilePath())
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
EnableBashCompletion: true,
|
EnableBashCompletion: true,
|
||||||
@ -515,3 +515,11 @@ func processFile(
|
|||||||
|
|
||||||
return target
|
return target
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func configFilePath() string {
|
||||||
|
fp, err := os.UserConfigDir()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
return filepath.Join(fp, "mark")
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user