Skip to content

Commit

Permalink
Use os.UserCacheDir to store boilerplates
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwhitaker committed Dec 14, 2023
1 parent 824fa13 commit bd62924
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,21 @@ import (
"fmt"
"io"
"io/fs"
"log"
"os"
"path/filepath"
"runtime"
"sort"
"strings"

"github.com/go-git/go-git/v5"
)

func RepoDir() string {
const gitignoreBoilerplatesDir = "gitignore-boilerplates"
const gitignoreBoilerplatesHiddenDir = "." + gitignoreBoilerplatesDir

override := os.Getenv("GIBO_BOILERPLATES")
if len(override) > 0 {
return override
}

override = os.Getenv("XDG_DATA_HOME")
if len(override) > 0 {
return filepath.Join(override, "gibo", gitignoreBoilerplatesDir)
}

if runtime.GOOS == "windows" {
override := os.Getenv("LOCALAPPDATA")
if len(override) > 0 {
return filepath.Join(override, gitignoreBoilerplatesDir)
}
cacheDir, err := os.UserCacheDir()
if err != nil {
log.Fatalln("gibo can't determine your user cache directory. Please file an issue at https://github.com/simonwhitaker/gibo/issues")
}

homeDir, _ := os.UserHomeDir()
return filepath.Join(homeDir, gitignoreBoilerplatesHiddenDir)
return filepath.Join(cacheDir, "gibo")
}

func cloneRepo(repo string) error {
Expand Down

1 comment on commit bd62924

@atsushifx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more better than I'm PR.

Please sign in to comment.