summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Treusch von Buttlar <martin.tvb@vitraum.de>2017-05-20 13:17:48 +0200
committerMartin Treusch von Buttlar <martin.tvb@vitraum.de>2017-05-20 13:17:48 +0200
commit4c03187fbef64573ded62f40d5d4dace6c48747b (patch)
tree2a4991b142afc022f5cebb1e2e0c19c091943661
parent6de9e9030108af25bf3c9cace0acc987f39ef2fd (diff)
refactor and add documentation for 'ponzu new'
-rw-r--r--cmd/ponzu/new.go9
-rw-r--r--cmd/ponzu/new_test.go4
2 files changed, 7 insertions, 6 deletions
diff --git a/cmd/ponzu/new.go b/cmd/ponzu/new.go
index 94e4697..0a19da1 100644
--- a/cmd/ponzu/new.go
+++ b/cmd/ponzu/new.go
@@ -32,14 +32,15 @@ Errors will be reported, but successful commands return nothing.`,
},
}
-func checkNmkAbs(gPath string) (string, error) {
+// name2path transforns a project name to an absolute path
+func name2path(projectName string) (string, error) {
gopath, err := getGOPATH()
if err != nil {
return "", err
}
gosrc := filepath.Join(gopath, "src")
- path := gPath
+ path := projectName
// support current directory
if path == "." {
path, err = os.Getwd()
@@ -56,7 +57,7 @@ func checkNmkAbs(gPath string) (string, error) {
return "", err
}
if len(srcrel) >= 2 && srcrel[:2] == ".." {
- return "", fmt.Errorf("path '%s' must be inside '%s'", gPath, gosrc)
+ return "", fmt.Errorf("path '%s' must be inside '%s'", projectName, gosrc)
}
if srcrel == "." {
return "", fmt.Errorf("path '%s' must not be %s", path, filepath.Join("GOPATH", "src"))
@@ -76,7 +77,7 @@ func checkNmkAbs(gPath string) (string, error) {
}
func newProjectInDir(path string) error {
- path, err := checkNmkAbs(path)
+ path, err := name2path(path)
if err != nil && !os.IsNotExist(err) {
return err
}
diff --git a/cmd/ponzu/new_test.go b/cmd/ponzu/new_test.go
index cda55a6..76cacb1 100644
--- a/cmd/ponzu/new_test.go
+++ b/cmd/ponzu/new_test.go
@@ -6,7 +6,7 @@ import (
"testing"
)
-func TestNewCheckNmkAbs(t *testing.T) {
+func TestNewName2Path(t *testing.T) {
savedGOPATH := os.Getenv("GOPATH")
defer os.Setenv("GOPATH", savedGOPATH)
pwd, err := os.Getwd()
@@ -55,7 +55,7 @@ func TestNewCheckNmkAbs(t *testing.T) {
if err != nil {
t.Fatalf("could not setup base: %s", err)
}
- got, gotE := checkNmkAbs(test.a)
+ got, gotE := name2path(test.a)
if got != test.wantP {
t.Errorf("got '%s', want: '%s'", got, test.wantP)
}