Add support for xdg specification config file (#32)

This commit is contained in:
Stewart Thomson
2020-05-11 12:14:47 -04:00
committed by GitHub
parent 13b13412aa
commit 0c81489742
4 changed files with 13 additions and 0 deletions

View File

@@ -141,6 +141,7 @@ OPTIONS:
Gotify-CLI will search the following paths for a config file:
* `/etc/gotify/cli.json`
* `$XDG_CONFIG_HOME/gotify/cli.json`
* `~/.gotify/cli.json`
* `./cli.json`

View File

@@ -4,11 +4,18 @@ import (
"os/user"
"path/filepath"
"runtime"
"github.com/adrg/xdg"
)
func GetLocations() (res []string) {
res = append(res, "./cli.json")
xdgPath, err := xdg.ConfigFile(filepath.Join("gotify", "cli.json"))
if err == nil {
res = append(res, xdgPath)
}
if usr, err := user.Current(); err == nil {
res = append(res, filepath.Join(usr.HomeDir, ".gotify", "cli.json"))
}

3
go.mod
View File

@@ -1,6 +1,7 @@
module github.com/gotify/cli/v2
require (
github.com/adrg/xdg v0.2.1
github.com/go-openapi/analysis v0.19.0 // indirect
github.com/go-openapi/errors v0.19.0 // indirect
github.com/go-openapi/jsonpointer v0.19.0 // indirect
@@ -19,3 +20,5 @@ require (
golang.org/x/sys v0.0.0-20190412213103-97732733099d // indirect
gopkg.in/urfave/cli.v1 v1.20.0
)
go 1.14

2
go.sum
View File

@@ -4,6 +4,8 @@ github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tN
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/adrg/xdg v0.2.1 h1:VSVdnH7cQ7V+B33qSJHTCRlNgra1607Q8PzEmnvb2Ic=
github.com/adrg/xdg v0.2.1/go.mod h1:ZuOshBmzV4Ta+s23hdfFZnBsdzmoR3US0d7ErpqSbTQ=
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf h1:eg0MeVzsP1G42dRafH3vf+al2vQIJU0YHX+1Tw87oco=
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=