Skip to content
This repository has been archived by the owner on Jun 25, 2022. It is now read-only.

Commit

Permalink
Remove dependency on gobuffalo/envy
Browse files Browse the repository at this point in the history
Closes #45

Credit to @dcelasun for the basis of the code
  • Loading branch information
Paul Bergeron committed Feb 8, 2018
1 parent 64c3dd4 commit 4915f0d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
3 changes: 1 addition & 2 deletions box.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"compress/gzip"

"github.com/gobuffalo/envy"
"github.com/pkg/errors"
)

Expand All @@ -34,7 +33,7 @@ func NewBox(path string) Box {
cov := filepath.Join("_test", "_obj_test")
cd = strings.Replace(cd, string(filepath.Separator)+cov, "", 1)
if !filepath.IsAbs(cd) && cd != "" {
cd = filepath.Join(envy.GoPath(), "src", cd)
cd = filepath.Join(GoPath(), "src", cd)
}

return Box{
Expand Down
4 changes: 2 additions & 2 deletions builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"path/filepath"
"testing"

"github.com/gobuffalo/envy"
"github.com/gobuffalo/packr"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -91,7 +91,7 @@ func Test_Binary_Builds(t *testing.T) {
r.NoError(err)

os.Chdir(root)
cmd := exec.Command(envy.Get("GO_BIN", "go"), "build", "-v", "-o", "bin/example")
cmd := exec.Command(packr.GoBin(), "build", "-v", "-o", "bin/example")
err = cmd.Run()
r.NoError(err)

Expand Down
27 changes: 27 additions & 0 deletions env.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package packr

import (
"go/build"
"os"
"strings"
)

// GoPath returns the current GOPATH env var
// or if it's missing, the default.
func GoPath() string {
go_path := strings.Split(os.Getenv("GOPATH"), string(os.PathListSeparator))
if len(go_path) == 0 || go_path[0] == "" {
return build.Default.GOPATH
}
return go_path[0]
}

// GoBin returns the current GO_BIN env var
// or if it's missing, a default of "go"
func GoBin() string {
go_bin := os.Getenv("GO_BIN")
if go_bin == "" {
return "go"
}
return go_bin
}
4 changes: 2 additions & 2 deletions packr/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"os/exec"

"github.com/gobuffalo/envy"
"github.com/gobuffalo/packr"
"github.com/gobuffalo/packr/builder"
"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand All @@ -26,7 +26,7 @@ var buildCmd = &cobra.Command{

cargs := []string{"build"}
cargs = append(cargs, args...)
cp := exec.Command(envy.Get("GO_BIN", "go"), cargs...)
cp := exec.Command(packr.GoBin(), cargs...)
cp.Stderr = os.Stderr
cp.Stdin = os.Stdin
cp.Stdout = os.Stdout
Expand Down
6 changes: 3 additions & 3 deletions packr/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"path/filepath"
"strings"

"github.com/gobuffalo/envy"
"github.com/gobuffalo/packr"
"github.com/gobuffalo/packr/builder"
"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand All @@ -22,7 +22,7 @@ var installCmd = &cobra.Command{
if len(args) > 0 {
input = args[len(args)-1]
if !strings.HasPrefix(input, ".") {
input = filepath.Join(envy.GoPath(), "src", input)
input = filepath.Join(packr.GoPath(), "src", input)
if _, err := os.Stat(input); err != nil {
return errors.WithStack(err)
}
Expand All @@ -37,7 +37,7 @@ var installCmd = &cobra.Command{

cargs := []string{"install"}
cargs = append(cargs, args...)
cp := exec.Command(envy.Get("GO_BIN", "go"), cargs...)
cp := exec.Command(packr.GoBin(), cargs...)
cp.Stderr = os.Stderr
cp.Stdin = os.Stdin
cp.Stdout = os.Stdout
Expand Down

0 comments on commit 4915f0d

Please sign in to comment.