From d0a2dc0569702db4cd8c6e62d17d4c2bbfec653a Mon Sep 17 00:00:00 2001 From: James Date: Mon, 10 Sep 2018 19:15:18 +0800 Subject: [PATCH 1/2] allow grift to run outside of $GOPATH (go module) --- cmd/grifter.go | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/cmd/grifter.go b/cmd/grifter.go index 6a21a1a..f742936 100644 --- a/cmd/grifter.go +++ b/cmd/grifter.go @@ -3,6 +3,7 @@ package cmd import ( "html/template" "os" + "path" "path/filepath" "strings" "sync" @@ -43,25 +44,34 @@ func newGrifter(name string) (*grifter, error) { CommandName: name, } - path, err := os.Getwd() + currentPath, err := os.Getwd() if err != nil { return g, errors.WithStack(err) } - for !strings.HasSuffix(path, "/src") && path != "/" { - if hasGriftDir(path) { - break - } + if strings.HasPrefix(currentPath, os.Getenv("GOPATH")) { + for !strings.HasSuffix(currentPath, "/src") && currentPath != "/" { + if hasGriftDir(currentPath) { + break + } - path = filepath.Dir(path) + currentPath = filepath.Dir(currentPath) + } + p := strings.SplitN(currentPath, filepath.FromSlash("/src/"), 2) + if len(p) == 1 { + return g, errors.Errorf("There is no directory named 'grifts'. Run '%s init' or switch to the appropriate directory", name) + } + g.GriftsAbsolutePath = filepath.ToSlash(filepath.Join(currentPath, "grifts")) + g.GriftsPackagePath = filepath.ToSlash(filepath.Join(p[1], "grifts")) + } else { + //is outside of gopath, dont loop to parent + if !hasGriftDir(currentPath) { + return g, errors.Errorf("There is no directory named 'grifts'. Run '%s init' or switch to the appropriate directory", name) + } + g.GriftsAbsolutePath = filepath.ToSlash(filepath.Join(currentPath, "grifts")) + g.GriftsPackagePath = filepath.ToSlash(filepath.Join(path.Base(currentPath), "grifts")) } - p := strings.SplitN(path, filepath.FromSlash("/src/"), 2) - if len(p) == 1 { - return g, errors.Errorf("There is no directory named 'grifts'. Run '%s init' or switch to the appropriate directory", name) - } - g.GriftsAbsolutePath = filepath.ToSlash(filepath.Join(path, "grifts")) - g.GriftsPackagePath = filepath.ToSlash(filepath.Join(p[1], "grifts")) return g, nil } From 0b02aa747bd44877277161b305099cadbfc69491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20K=C3=A4ufl?= Date: Fri, 31 Aug 2018 12:23:53 +0200 Subject: [PATCH 2/2] Update test matrix --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a7ec5df..c760b65 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,9 @@ language: go sudo: false go: - - 1.8.3 + - 1.9.x + - 1.10.x + - 1.11.x - tip matrix: