Skip to content

Commit

Permalink
replace GOPATH env var lookups with getGOPATH func throughout codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
nilslice committed Mar 1, 2017
1 parent d7f88d9 commit ad6220d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
14 changes: 10 additions & 4 deletions cmd/ponzu/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ import (

func newProjectInDir(path string) error {
// set path to be nested inside $GOPATH/src
gopath := os.Getenv("GOPATH")
gopath, err := getGOPATH()
if err != nil {
return err
}
path = filepath.Join(gopath, "src", path)

// check if anything exists at the path, ask if it should be overwritten
if _, err := os.Stat(path); !os.IsNotExist(err) {
if _, err = os.Stat(path); !os.IsNotExist(err) {
fmt.Println("Path exists, overwrite contents? (y/N):")

answer, err := getAnswer()
Expand Down Expand Up @@ -67,7 +70,10 @@ func getAnswer() (string, error) {
}

func createProjectInDir(path string) error {
gopath := os.Getenv("GOPATH")
gopath, err := getGOPATH()
if err != nil {
return err
}
repo := ponzuRepo
local := filepath.Join(gopath, "src", filepath.Join(repo...))
network := "https://" + strings.Join(repo, "/") + ".git"
Expand All @@ -76,7 +82,7 @@ func createProjectInDir(path string) error {
}

// create the directory or overwrite it
err := os.MkdirAll(path, os.ModeDir|os.ModePerm)
err = os.MkdirAll(path, os.ModeDir|os.ModePerm)
if err != nil {
return err
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/ponzu/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"
)
Expand Down Expand Up @@ -180,7 +179,10 @@ func ponzu(isCLI bool) (map[string]interface{}, error) {

info := filepath.Join("cmd", "ponzu", "ponzu.json")
if isCLI {
gopath := os.Getenv("GOPATH")
gopath, err := getGOPATH()
if err != nil {
return nil, err
}
repo := filepath.Join(gopath, "src", "github.com", "ponzu-cms", "ponzu")
info = filepath.Join(repo, "cmd", "ponzu", "ponzu.json")
}
Expand Down

0 comments on commit ad6220d

Please sign in to comment.