Skip to content

Commit

Permalink
dep diet
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates committed Jun 26, 2019
1 parent b89dc1b commit df35401
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
19 changes: 9 additions & 10 deletions cmd/grifter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"sync"

"github.com/gobuffalo/envy"
"github.com/pkg/errors"
"github.com/rogpeppe/go-internal/modfile"
)

Expand Down Expand Up @@ -50,7 +49,7 @@ func newGrifter(name string) (*grifter, error) {

currentPath, err := os.Getwd()
if err != nil {
return g, errors.WithStack(err)
return g, err
}

if envy.InGoPath() {
Expand All @@ -64,26 +63,26 @@ func newGrifter(name string) (*grifter, error) {
}
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)
return g, fmt.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)
return g, fmt.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"))

// check for go module to see if we can get go.mod
if envy.Mods() {
moddata, err := ioutil.ReadFile("go.mod")
if err != nil {
return g, errors.New("go.mod cannot be read or does not exist while go module is enabled.")
return g, fmt.Errorf("go.mod cannot be read or does not exist while go module is enabled.")
}
packagePath := modfile.ModulePath(moddata)
if packagePath == "" {
return g, errors.New("go.mod is malformed.")
return g, fmt.Errorf("go.mod is malformed.")
}
g.GriftsPackagePath = fmt.Sprintf("%s/grifts", packagePath)
} else {
Expand All @@ -101,7 +100,7 @@ func (g *grifter) Setup() error {
root := filepath.Dir(exePath)
err := os.MkdirAll(root, 0755)
if err != nil {
return errors.WithStack(err)
return err
}

tmpls := map[string]string{}
Expand All @@ -112,17 +111,17 @@ func (g *grifter) Setup() error {
for k, v := range tmpls {
t, err := template.New(k).Parse(v)
if err != nil {
return errors.WithStack(err)
return err
}

f, err := os.Create(k)
if err != nil {
return errors.WithStack(err)
return err
}

err = t.Execute(f, g)
if err != nil {
return errors.WithStack(err)
return err
}
}

Expand Down
11 changes: 5 additions & 6 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os/exec"

"github.com/markbates/grift/grift"
"github.com/pkg/errors"
)

var currentGrift *grifter
Expand Down Expand Up @@ -35,12 +34,12 @@ func Run(name string, args []string) error {

err := setup(name)
if err != nil {
return errors.WithStack(err)
return err
}

err = run(args)
if err != nil {
return errors.WithStack(err)
return err
}

return nil
Expand All @@ -61,7 +60,7 @@ func run(args []string) error {
rargs = append(rargs, exePath)
rargs = append(rargs, args...)
if err := grift.RunSource(exec.Command("go", rargs...)); err != nil {
return errors.WithStack(err)
return err
}
return nil
}
Expand All @@ -75,11 +74,11 @@ func setup(name string) error {
var err error
currentGrift, err = newGrifter(name)
if err != nil {
return errors.WithStack(err)
return err
}
err = currentGrift.Setup()
if err != nil {
return errors.WithStack(err)
return err
}
return nil
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module github.com/markbates/grift

go 1.12

require (
github.com/gobuffalo/envy v1.7.0
github.com/pkg/errors v0.8.1
github.com/rogpeppe/go-internal v1.3.0
github.com/stretchr/testify v1.3.0
)
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqx
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand Down

0 comments on commit df35401

Please sign in to comment.