Skip to content

Commit

Permalink
fix: load config on macOS
Browse files Browse the repository at this point in the history
On macOS, `os.UserConfigDir` returns `$HOME/Library/Application Support`
and not `~/.config`. This patch uses a module that works across OSes.

Fixes mattn#3
  • Loading branch information
bndw committed Apr 1, 2023
1 parent f3236ef commit cab839f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.20

require (
github.com/fatih/color v1.15.0
github.com/mitchellh/go-homedir v1.1.0
github.com/nbd-wtf/go-nostr v0.15.1
github.com/urfave/cli/v2 v2.25.0
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98=
github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/nbd-wtf/go-nostr v0.15.1 h1:a3lGlEVNOtXpxv8VA3+rdtX5PCoYKXKAOpcr4cQFgO8=
github.com/nbd-wtf/go-nostr v0.15.1/go.mod h1:qFFTIxh15H5GGN0WsBI/P73DteqsevnhSEW/yk8nEf4=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
Expand Down
18 changes: 17 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import (
"log"
"os"
"path/filepath"
"runtime"
"sort"
"strings"
"sync"
"sync/atomic"
"time"

"github.com/mitchellh/go-homedir"
"github.com/urfave/cli/v2"

"github.com/fatih/color"
Expand Down Expand Up @@ -60,8 +62,22 @@ type Profile struct {
Name string `json:"name"`
}

func configDir() (string, error) {
switch runtime.GOOS {
case "darwin":
dir, err := homedir.Dir()
if err != nil {
return "", err
}
return filepath.Join(dir, ".config"), nil
default:
return os.UserConfigDir()

}
}

func loadConfig(profile string) (*Config, error) {
dir, err := os.UserConfigDir()
dir, err := configDir()
if err != nil {
return nil, err
}
Expand Down

0 comments on commit cab839f

Please sign in to comment.