Skip to content

Commit

Permalink
use hidden folder if XDG_CONFIG_HOME is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
HandOfGod94 committed Nov 18, 2023
1 parent 8a216c5 commit 96575dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions pkg/jira_changelog/jira/config_service/config_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"golang.org/x/exp/slog"
)

const configDirName = "gh-jira-changelog"

func Save(v any, filepath string) error {
confdir, err := getOrCreateConfDir()
if err != nil {
Expand Down Expand Up @@ -70,17 +72,17 @@ func Clear() error {
return nil
}

func defaultConfDir() (res string, err error) {
filepath := path.Join("gh-jira-changelog")
res = os.Getenv("XDG_CONFIG_HOME")
if res == "" {
res, err = homedir.Dir()
func defaultConfDir() (string, error) {
userDefaultConfLocation := os.Getenv("XDG_CONFIG_HOME")
if userDefaultConfLocation == "" {
dir, err := homedir.Dir()
if err != nil {
return
return "", err
}
return path.Join(dir, "."+configDirName), nil
}

return path.Join(res, filepath), nil
return path.Join(userDefaultConfLocation, configDirName), nil
}

func getOrCreateConfDir() (string, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestDefaultDir_When_XDG_CONFIG_HOME_isNotSet(t *testing.T) {
os.Unsetenv("XDG_CONFIG_HOME")

homeDir, _ := homedir.Dir()
expected := path.Join(homeDir, "gh-jira-changelog")
expected := path.Join(homeDir, ".gh-jira-changelog")

got, err := defaultConfDir()

Expand Down

0 comments on commit 96575dc

Please sign in to comment.