Skip to content

Commit

Permalink
Merge pull request #2 from tommy6073/make-config-dir-if-not-exists
Browse files Browse the repository at this point in the history
Make config directory if not exists when saving config
  • Loading branch information
harakeishi authored Oct 31, 2022
2 parents 056156e + 4c50c15 commit 4053068
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion trv/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/google/go-github/github"
"golang.org/x/oauth2"
Expand Down Expand Up @@ -57,7 +58,11 @@ func (c *Config) addSource(s Source) {
func (c Config) saveConfig() {
home, _ := os.UserHomeDir()
file, _ := json.MarshalIndent(c, "", " ")
_ = ioutil.WriteFile(fmt.Sprintf("%s/.trv/config.json", home), file, 0644)
dir := filepath.Join(home, ".trv")
if _, err := os.Stat(dir); os.IsNotExist(err) {
_ = os.Mkdir(dir, 0755)
}
_ = ioutil.WriteFile(filepath.Join(dir, "config.json"), file, 0644)
}

func (s Source) NewClient() (*github.Client, context.Context, error) {
Expand Down

0 comments on commit 4053068

Please sign in to comment.