remove roundabout way of getting config dir
This commit is contained in:
parent
5c660f013b
commit
044c944262
|
@ -14,6 +14,7 @@ import (
|
|||
"git.burning.moe/celediel/agedit/pkg/encrypt"
|
||||
"git.burning.moe/celediel/agedit/pkg/env"
|
||||
|
||||
"github.com/adrg/xdg"
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/ilyakaznacheev/cleanenv"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
@ -39,6 +40,7 @@ COPYRIGHT:
|
|||
{{.Copyright}}
|
||||
{{end}}
|
||||
`
|
||||
sep string = string(os.PathSeparator)
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -170,7 +172,7 @@ func before(ctx *cli.Context) error {
|
|||
// set some defaults
|
||||
cfg = config.Defaults
|
||||
cfg.Editor = env.GetEditor()
|
||||
cfg_dir := env.GetConfigDir(name)
|
||||
cfg_dir := xdg.ConfigHome + sep + name + sep
|
||||
cfg.IdentityFile = cfg_dir + "identity.key"
|
||||
configFile = cfg_dir + name + ".yaml"
|
||||
logger = log.NewWithOptions(os.Stderr, log.Options{
|
||||
|
|
41
pkg/env/env.go
vendored
41
pkg/env/env.go
vendored
|
@ -5,8 +5,6 @@ import (
|
|||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/adrg/xdg"
|
||||
)
|
||||
|
||||
// GetEditor gets the configured editor by checking environmental
|
||||
|
@ -24,24 +22,6 @@ func GetEditor() string {
|
|||
return editor
|
||||
}
|
||||
|
||||
// GetConfigDir gets a config directory based from environmental variables + the app name
|
||||
//
|
||||
// On Windows, %APPDATA%\agedit is used
|
||||
//
|
||||
// On UNIX-like systems, $XDG_CONFIG_HOME/agedit is tried, if it isn't defined, $HOME/.config/agedit is used
|
||||
func GetConfigDir(appname string) string {
|
||||
return make_path(xdg.ConfigHome, appname)
|
||||
}
|
||||
|
||||
// GetConfigDir gets a config directory based from environmental variables + the app name
|
||||
//
|
||||
// On Windows, %LOCALAPPDATA%\agedit is used
|
||||
//
|
||||
// On UNIX-like systems, $XDG_DATA_HOME/agedit is tried, if it isn't defined, $HOME/.local/share/agedit is used
|
||||
func GetDataDir(appname string) string {
|
||||
return make_path(xdg.DataHome, appname)
|
||||
}
|
||||
|
||||
// GetTempDirectory returns the systems temporary directory
|
||||
//
|
||||
// returns %TEMP% on Windows, /tmp on UNIX-like systems
|
||||
|
@ -65,24 +45,3 @@ func GetTempDirectory() string {
|
|||
}
|
||||
return tmp
|
||||
}
|
||||
|
||||
func make_path(paths ...string) string {
|
||||
sep := string(os.PathSeparator)
|
||||
output := strings.Builder{}
|
||||
|
||||
// add / to the start if it's not already there and we're not on Windows
|
||||
if match, err := regexp.Match("^\\w", []byte(paths[0])); err == nil && match && runtime.GOOS != "windows" {
|
||||
output.WriteString(sep)
|
||||
}
|
||||
|
||||
for _, path := range paths {
|
||||
// don't add / to the end if it's there
|
||||
if strings.HasSuffix(path, sep) {
|
||||
output.WriteString(path)
|
||||
} else {
|
||||
output.WriteString(path + sep)
|
||||
}
|
||||
}
|
||||
|
||||
return output.String()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue