-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
631 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package depgen | ||
|
||
import ( | ||
"os/exec" | ||
|
||
"github.com/gobuffalo/genny" | ||
) | ||
|
||
func Ensure(verbose bool) (*genny.Generator, error) { | ||
g := genny.New() | ||
|
||
var args []string | ||
if verbose { | ||
args = append(args, "-v") | ||
} | ||
|
||
id, err := InstallDep(args...) | ||
if err != nil { | ||
return g, err | ||
} | ||
g.Merge(id) | ||
|
||
cmd := exec.Command("dep", "ensure") | ||
if verbose { | ||
cmd.Args = append(cmd.Args, args...) | ||
} | ||
g.Command(cmd) | ||
return g, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package depgen | ||
|
||
import ( | ||
"os/exec" | ||
|
||
"github.com/gobuffalo/genny" | ||
) | ||
|
||
func Init(path string, verbose bool) (*genny.Generator, error) { | ||
g := genny.New() | ||
var args []string | ||
if verbose { | ||
args = append(args, "-v") | ||
} | ||
|
||
id, err := InstallDep(args...) | ||
if err != nil { | ||
return g, err | ||
} | ||
g.Merge(id) | ||
|
||
cmd := exec.Command("dep", "init") | ||
if verbose { | ||
cmd.Args = append(cmd.Args, args...) | ||
} | ||
g.Command(cmd) | ||
return g, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package depgen | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/gobuffalo/genny" | ||
"github.com/gobuffalo/genny/gentest" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_Init_WithDep(t *testing.T) { | ||
r := require.New(t) | ||
|
||
run := gentest.NewRunner() | ||
run.LookPathFn = func(s string) (string, error) { | ||
if s == "dep" { | ||
return "dep", nil | ||
} | ||
return exec.LookPath(s) | ||
} | ||
|
||
err := run.WithNew(Init("", false)) | ||
r.NoError(err) | ||
|
||
r.NoError(run.Run()) | ||
|
||
res := run.Results() | ||
|
||
r.Len(res.Commands, 1) | ||
|
||
c := res.Commands[0] | ||
r.Equal("dep init", strings.Join(c.Args, " ")) | ||
} | ||
|
||
func Test_Init_WithoutDep(t *testing.T) { | ||
r := require.New(t) | ||
|
||
run := gentest.NewRunner() | ||
run.LookPathFn = func(s string) (string, error) { | ||
if s == "dep" { | ||
return "", os.ErrNotExist | ||
} | ||
return exec.LookPath(s) | ||
} | ||
|
||
err := run.WithNew(Init("", false)) | ||
r.NoError(err) | ||
|
||
r.NoError(run.Run()) | ||
|
||
res := run.Results() | ||
|
||
r.Len(res.Commands, 2) | ||
|
||
c := res.Commands[0] | ||
r.Equal(genny.GoBin()+" get github.com/golang/dep/cmd/dep", strings.Join(c.Args, " ")) | ||
|
||
c = res.Commands[1] | ||
r.Equal("dep init", strings.Join(c.Args, " ")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package depgen | ||
|
||
import ( | ||
"os/exec" | ||
|
||
"github.com/gobuffalo/genny" | ||
) | ||
|
||
func InstallDep(args ...string) (*genny.Generator, error) { | ||
g := genny.New() | ||
g.RunFn(func(r *genny.Runner) error { | ||
if _, err := r.LookPath("dep"); err == nil { | ||
return nil | ||
} | ||
|
||
args = append([]string{"get"}, args...) | ||
args = append(args, "github.com/golang/dep/cmd/dep") | ||
c := exec.Command(genny.GoBin(), args...) | ||
return r.Exec(c) | ||
}) | ||
return g, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package depgen | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/gobuffalo/envy" | ||
"github.com/gobuffalo/genny/gentest" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_InstallDep_NotInstalled(t *testing.T) { | ||
envy.Set("GO_BIN", "go") | ||
r := require.New(t) | ||
|
||
run := gentest.NewRunner() | ||
run.LookPathFn = func(s string) (string, error) { | ||
return s, errors.New("couldn't find dep") | ||
} | ||
run.WithNew(InstallDep()) | ||
r.NoError(run.Run()) | ||
|
||
res := run.Results() | ||
|
||
cmds := []string{"go get github.com/golang/dep/cmd/dep"} | ||
r.Len(res.Commands, len(cmds)) | ||
} | ||
|
||
func Test_InstallDep_Installed(t *testing.T) { | ||
envy.Set("GO_BIN", "go") | ||
r := require.New(t) | ||
|
||
run := gentest.NewRunner() | ||
run.LookPathFn = func(s string) (string, error) { | ||
return s, nil | ||
} | ||
run.WithNew(InstallDep()) | ||
r.NoError(run.Run()) | ||
|
||
res := run.Results() | ||
r.Len(res.Commands, 0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package depgen | ||
|
||
import ( | ||
"os/exec" | ||
|
||
"github.com/gobuffalo/genny" | ||
) | ||
|
||
func Update(verbose bool) (*genny.Generator, error) { | ||
g := genny.New() | ||
var args []string | ||
if verbose { | ||
args = append(args, "-v") | ||
} | ||
|
||
id, err := InstallDep(args...) | ||
if err != nil { | ||
return g, err | ||
} | ||
g.Merge(id) | ||
|
||
cmd := exec.Command("dep", "ensure") | ||
args = append(args, "-update") | ||
if verbose { | ||
cmd.Args = append(cmd.Args, args...) | ||
} | ||
return g, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package depgen | ||
|
||
// Version of depgen | ||
const Version = "v0.2.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1 @@ | ||
package genny_test | ||
|
||
// // exampleLogger just cleans up variable log content | ||
// // such as GOPATH, step names, etc.... | ||
// // without this Go Example tests won't work. | ||
// func exampleLogger(l *gentest.Logger) genny.Logger { | ||
// l.CloseFn = func() error { | ||
// s := l.Stream.String() | ||
// c := build.Default | ||
// for _, src := range c.SrcDirs() { | ||
// s = strings.Replace(s, src, "/go/src", -1) | ||
// } | ||
// s = strings.Replace(s, "\\", "/", -1) | ||
// | ||
// for i, line := range strings.Split(s, "\n") { | ||
// if strings.Contains(line, "Step:") { | ||
// s = strings.Replace(s, line, fmt.Sprintf("[DEBU] Step: %d", i+1), 1) | ||
// } | ||
// } | ||
// fmt.Print(s) | ||
// return nil | ||
// } | ||
// return l | ||
// } | ||
// | ||
// func ExampleGenerator_withCommand() { | ||
// // create a new `*genny.Generator` | ||
// g := genny.New() | ||
// | ||
// g.Command(exec.Command("go", "version")) | ||
// | ||
// // create a new `*genny.Runner` | ||
// r := genny.NewRunner(context.Background()) | ||
// | ||
// // add a new logger to clean and dump output | ||
// // for the example tests | ||
// r.Logger = exampleLogger(gentest.NewLogger()) | ||
// | ||
// // add the generator to the `*genny.Runner`. | ||
// r.With(g) | ||
// | ||
// // run the runner | ||
// if err := r.Run(); err != nil { | ||
// log.Fatal(err) | ||
// } | ||
// // Output: | ||
// // [DEBU] Step: 1 | ||
// // [DEBU] Chdir: /go/src/github.com/gobuffalo/genny | ||
// // [DEBU] Exec: go version | ||
// } | ||
// | ||
// func ExampleGenerator_withFile() { | ||
// // create a new `*genny.Generator` | ||
// g := genny.New() | ||
// | ||
// // add a file named `index.html` that has a body of `Hello\n` | ||
// // to the generator | ||
// g.File(genny.NewFileS("index.html", "Hello\n")) | ||
// | ||
// // create a new `*genny.Runner` | ||
// r := genny.NewRunner(context.Background()) | ||
// | ||
// // add a new logger to clean and dump output | ||
// // for the example tests | ||
// r.Logger = exampleLogger(gentest.NewLogger()) | ||
// | ||
// // add the generator to the `*genny.Runner`. | ||
// r.With(g) | ||
// | ||
// // run the runner | ||
// if err := r.Run(); err != nil { | ||
// log.Fatal(err) | ||
// } | ||
// // Output: | ||
// // [DEBU] Step: 1 | ||
// // [DEBU] Chdir: /go/src/github.com/gobuffalo/genny | ||
// // [DEBU] File: /go/src/github.com/gobuffalo/genny/index.html | ||
// } | ||
// | ||
// func ExampleRunner() { | ||
// // create a new `*genny.Runner` | ||
// r := genny.NewRunner(context.Background()) | ||
// | ||
// // add a new logger to clean and dump output | ||
// // for the example tests | ||
// r.Logger = exampleLogger(gentest.NewLogger()) | ||
// | ||
// // add the generator(s) to the `*genny.Runner`. | ||
// // r.With(g) | ||
// | ||
// // run the runner | ||
// if err := r.Run(); err != nil { | ||
// log.Fatal(err) | ||
// } | ||
// } |
Oops, something went wrong.