Skip to content

Commit

Permalink
dep diet (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates authored Jun 24, 2019
1 parent 62e7907 commit f1b591b
Show file tree
Hide file tree
Showing 26 changed files with 322 additions and 166 deletions.
3 changes: 1 addition & 2 deletions cmd/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/gobuffalo/genny"
"github.com/gobuffalo/release/genny/azure"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

Expand All @@ -27,7 +26,7 @@ var azureCmd = &cobra.Command{

opts := azureOptions.Options
if err := run.WithNew(azure.New(opts)); err != nil {
return errors.WithStack(err)
return err
}

return run.Run()
Expand Down
7 changes: 3 additions & 4 deletions cmd/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"

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

Expand All @@ -33,7 +32,7 @@ var doctorCmd = &cobra.Command{
c := exec.Command("git", "version")
b, err := c.CombinedOutput()
if err != nil {
return errors.WithStack(err)
return err
}
gv := strings.TrimSpace(string(b))
fmt.Printf("Git is installed: %s (%s)\n", p, gv)
Expand All @@ -51,7 +50,7 @@ var doctorCmd = &cobra.Command{
c := exec.Command("goreleaser", "-v")
b, err := c.CombinedOutput()
if err != nil {
return errors.WithStack(err)
return err
}
gv := strings.TrimSpace(string(b))
fmt.Printf("Goreleaser is installed: %s (%s)\n", p, gv)
Expand All @@ -62,7 +61,7 @@ var doctorCmd = &cobra.Command{
}

if found {
return errors.New("your system is NOT ready to release")
return fmt.Errorf("your system is NOT ready to release")
}

fmt.Println("your system is ready to release")
Expand Down
3 changes: 1 addition & 2 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/gobuffalo/genny"
"github.com/gobuffalo/release/genny/initgen"
"github.com/gobuffalo/release/genny/makefile"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -36,7 +35,7 @@ var initCmd = &cobra.Command{

gg, err := initgen.New(opts)
if err != nil {
return errors.WithStack(err)
return err
}
run.WithGroup(gg)

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

"github.com/gobuffalo/genny"
"github.com/gobuffalo/release/genny/release"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -45,7 +44,7 @@ var rootCmd = &cobra.Command{
var err error
opts.Version, err = askForVersion()
if err != nil {
return errors.WithStack(err)
return err
}
}

Expand All @@ -56,7 +55,7 @@ var rootCmd = &cobra.Command{

g, err := release.New(opts)
if err != nil {
return errors.WithStack(err)
return err
}
run.With(g)

Expand All @@ -72,7 +71,7 @@ var rootCmd = &cobra.Command{
if err := run.Exec(c); err != nil {
run.Logger.Error(err)
}
return errors.WithStack(err)
return err
}
return nil
},
Expand All @@ -90,7 +89,7 @@ func askForVersion() (string, error) {
cmd := exec.Command("git", "tag", "--sort", "-creatordate")
b, err := cmd.CombinedOutput()
if err != nil {
return "", errors.WithStack(err)
return "", err
}

lines := strings.Split(string(b), "\n")
Expand All @@ -105,7 +104,7 @@ func askForVersion() (string, error) {
fmt.Print("Enter version number (vx.x.x): ")
v, err := r.ReadString('\n')
if err != nil {
return "", errors.WithStack(err)
return "", err
}
v = strings.TrimSpace(v)
return v, nil
Expand Down
7 changes: 3 additions & 4 deletions genny/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@ package azure

import (
"github.com/gobuffalo/genny"
"github.com/gobuffalo/genny/plushgen"
"github.com/gobuffalo/packr/v2"
"github.com/gobuffalo/plush"
"github.com/gobuffalo/plushgen"
"github.com/pkg/errors"
)

func New(opts *Options) (*genny.Generator, error) {
g := genny.New()

if err := opts.Validate(); err != nil {
return g, errors.WithStack(err)
return g, err
}
box := packr.New("github.com/gobuffalo/release/genny/azure/templates", "../azure/templates")
if err := genny.ForceBox(g, box, opts.Force); err != nil {
return g, errors.WithStack(err)
return g, err
}
ctx := plush.NewContext()
ctx.Set("opts", opts)
Expand Down
7 changes: 3 additions & 4 deletions genny/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import (
"os/exec"

"github.com/gobuffalo/genny"
"github.com/gobuffalo/genny/plushgen"
"github.com/gobuffalo/packr/v2"
"github.com/gobuffalo/plush"
"github.com/gobuffalo/plushgen"
"github.com/pkg/errors"
)

func New(opts *Options) (*genny.Generator, error) {
Expand All @@ -16,11 +15,11 @@ func New(opts *Options) (*genny.Generator, error) {

g.Command(exec.Command("git", "init"))
if err := opts.Validate(); err != nil {
return g, errors.WithStack(err)
return g, err
}

if err := g.Box(packr.New("release:genny/git", "../git/templates")); err != nil {
return g, errors.WithStack(err)
return g, err
}
ctx := plush.NewContext()
ctx.Set("opts", opts)
Expand Down
9 changes: 4 additions & 5 deletions genny/goreleaser/goreleaser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,26 @@ import (
"html/template"

"github.com/gobuffalo/genny"
"github.com/gobuffalo/genny/movinglater/gotools"
"github.com/gobuffalo/genny/gogen"
"github.com/gobuffalo/packr/v2"
"github.com/pkg/errors"
)

func New(opts *Options) (*genny.Generator, error) {
g := genny.New()

if err := opts.Validate(); err != nil {
return g, errors.WithStack(err)
return g, err
}

box := packr.New("release:genny:goreleaser", "../goreleaser/templates")
if err := genny.ForceBox(g, box, opts.Force); err != nil {
return g, errors.WithStack(err)
return g, err
}

data := map[string]interface{}{
"opts": opts,
}
g.Transformer(gotools.TemplateTransformer(data, template.FuncMap{}))
g.Transformer(gogen.TemplateTransformer(data, template.FuncMap{}))

g.Transformer(genny.Dot())
return g, nil
Expand Down
11 changes: 5 additions & 6 deletions genny/goreleaser/options.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package goreleaser

import (
"fmt"
"os/user"
"path/filepath"

"github.com/pkg/errors"
)

type Options struct {
Expand All @@ -18,26 +17,26 @@ type Options struct {
// Validate that options are usuable
func (opts *Options) Validate() error {
if len(opts.MainFile) == 0 {
return errors.New("goreleaser is only for binary applications")
return fmt.Errorf("goreleaser is only for binary applications")
}
if len(opts.BrewTap) == 0 {
opts.BrewTap = "homebrew-tap"
}

if len(opts.Root) == 0 {
return errors.New("root can not be empty")
return fmt.Errorf("root can not be empty")
}

if len(opts.BrewOwner) == 0 {
user, err := user.Current()
if err != nil {
return errors.WithStack(err)
return err
}
opts.BrewOwner = user.Username
}
if len(opts.MainFile) > 0 {
if filepath.Ext(opts.MainFile) != ".go" {
return errors.Errorf("%s is not a .go file", opts.MainFile)
return fmt.Errorf("%s is not a .go file", opts.MainFile)
}
}
return nil
Expand Down
19 changes: 9 additions & 10 deletions genny/initgen/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@ package initgen

import (
"github.com/gobuffalo/genny"
"github.com/gobuffalo/genny/movinglater/gotools/gomods"
"github.com/gobuffalo/genny/gogen/gomods"
"github.com/gobuffalo/licenser/genny/licenser"
"github.com/gobuffalo/release/genny/azure"
"github.com/gobuffalo/release/genny/git"
"github.com/gobuffalo/release/genny/goreleaser"
"github.com/gobuffalo/release/genny/makefile"
"github.com/gobuffalo/release/genny/release"
"github.com/pkg/errors"
)

func New(opts *Options) (*genny.Group, error) {
gg := &genny.Group{}

if err := opts.Validate(); err != nil {
return gg, errors.WithStack(err)
return gg, err
}
g := genny.New()
g.Transformer(genny.Dot())
Expand All @@ -27,7 +26,7 @@ func New(opts *Options) (*genny.Group, error) {
Root: opts.Root,
})
if err != nil {
return gg, errors.WithStack(err)
return gg, err
}
gg.Add(g)

Expand All @@ -45,15 +44,15 @@ func New(opts *Options) (*genny.Group, error) {
// set up go mods if enabled
g, err = gomods.Init("", opts.Root)
if err != nil {
return gg, errors.WithStack(err)
return gg, err
}
gg.Add(g)

g, err = azure.New(&azure.Options{
Force: opts.Force,
})
if err != nil {
return gg, errors.WithStack(err)
return gg, err
}
gg.Add(g)

Expand All @@ -66,14 +65,14 @@ func New(opts *Options) (*genny.Group, error) {
// write a new makefile
g, err = makefile.New(opts.Options)
if err != nil {
return gg, errors.WithStack(err)
return gg, err
}
gg.Add(g)

// generate a license
g, err = licenser.New(&licenser.Options{})
if err != nil {
return gg, errors.WithStack(err)
return gg, err
}
gg.Add(g)

Expand All @@ -85,15 +84,15 @@ func New(opts *Options) (*genny.Group, error) {
Root: opts.Root,
})
if err != nil {
return gg, errors.WithStack(err)
return gg, err
}
gg.Add(g)
}

// run go mod tidy again at the end
g, err = gomods.Tidy(opts.Root, false)
if err != nil {
return gg, errors.WithStack(err)
return gg, err
}
gg.Add(g)
return gg, nil
Expand Down
2 changes: 1 addition & 1 deletion genny/initgen/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/gobuffalo/genny"
"github.com/gobuffalo/genny/gentest"
"github.com/gobuffalo/genny/movinglater/gotools/gomods"
"github.com/gobuffalo/genny/gogen/gomods"
"github.com/gobuffalo/release/genny/makefile"
"github.com/stretchr/testify/require"
)
Expand Down
6 changes: 3 additions & 3 deletions genny/initgen/options.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package initgen

import (
"fmt"
"os"
"path/filepath"

"github.com/gobuffalo/release/genny/makefile"
"github.com/pkg/errors"
)

type Options struct {
Expand All @@ -18,7 +18,7 @@ type Options struct {
// Validate that options are usuable
func (opts *Options) Validate() error {
if len(opts.Root) == 0 {
return errors.New("root can not be empty")
return fmt.Errorf("root can not be empty")
}
if len(opts.Version) == 0 {
opts.Version = "v0.0.1"
Expand All @@ -28,7 +28,7 @@ func (opts *Options) Validate() error {
}
if len(opts.MainFile) > 0 {
if filepath.Ext(opts.MainFile) != ".go" {
return errors.Errorf("%s is not a .go file", opts.MainFile)
return fmt.Errorf("%s is not a .go file", opts.MainFile)
}
} else {
if _, err := os.Stat(filepath.Join(opts.Root, "main.go")); err == nil {
Expand Down
Loading

0 comments on commit f1b591b

Please sign in to comment.