Skip to content

Commit

Permalink
Resovle issue for finding config path of Mac (#283)
Browse files Browse the repository at this point in the history
* Resovle issue for finding config path of Mac

* Remove printing config log file path
  • Loading branch information
weherdh authored Nov 16, 2022
1 parent b86232b commit 6ba715f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 19 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.17

require (
github.com/PagerDuty/go-pagerduty v1.5.1
github.com/adrg/xdg v0.4.0
github.com/aws/aws-sdk-go v1.44.66
github.com/coreos/go-semver v0.3.0
github.com/deckarep/golang-set v1.7.1
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
github.com/a8m/tree v0.0.0-20210115125333-10a5fd5b637d/go.mod h1:FSdwKX97koS5efgm8WevNf7XS3PqtyFkKDDXrz778cg=
github.com/acomagu/bufpipe v1.0.3/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E=
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
Expand Down Expand Up @@ -2205,7 +2203,6 @@ golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211029165221-6e7872819dc8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
18 changes: 3 additions & 15 deletions pkg/osdctlConfig/osdctlConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,19 @@ import (
"errors"
"os"

"github.com/adrg/xdg"
"github.com/spf13/viper"
)

const (
ConfigFileName = "osdctl"
ConfifFilePath = "~/.config"
)

// Generates the config file path for osdctl config
func generateConfigFilePath() (string, error) {
configFilePath, err := xdg.ConfigFile(ConfigFileName)
if err != nil {
return "", err
}
return configFilePath, nil
}

func EnsureConfigFile() error {
configFilePath, err := generateConfigFilePath()
configHomePath, err := os.UserHomeDir()
if err != nil {
return err
}

configFilePath := configHomePath + "/.config/" + ConfigFileName
if _, err := os.Stat(configFilePath); errors.Is(err, os.ErrNotExist) {
_, err = os.Create(configFilePath)
if err != nil {
Expand All @@ -41,6 +30,5 @@ func EnsureConfigFile() error {
if err := viper.ReadInConfig(); err != nil {
return err
}

return err
return nil
}

0 comments on commit 6ba715f

Please sign in to comment.