Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
set the root module/package name at app creation fixes #1329
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates committed Dec 10, 2018
1 parent ce68c39 commit 0813411
Show file tree
Hide file tree
Showing 7 changed files with 283 additions and 277 deletions.
22 changes: 17 additions & 5 deletions buffalo/cmd/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (

type newAppOptions struct {
Options *core.Options
Module string
Force bool
Verbose bool
DryRun bool
Expand All @@ -49,6 +50,7 @@ func parseNewOptions(args []string) (newAppOptions, error) {
Force: viper.GetBool("force"),
Verbose: viper.GetBool("verbose"),
DryRun: viper.GetBool("dry-run"),
Module: viper.GetString("module"),
}

if len(args) == 0 {
Expand All @@ -73,12 +75,13 @@ func parseNewOptions(args []string) (newAppOptions, error) {
app.Root = filepath.Join(app.Root, app.Name.File().String())
}

aa := meta.New(app.Root)
if len(nopts.Module) == 0 {
aa := meta.New(app.Root)
app.PackageRoot(aa.PackagePkg)
} else {
app.PackageRoot(nopts.Module)
}

app.ActionsPkg = aa.ActionsPkg
app.GriftsPkg = aa.GriftsPkg
app.ModelsPkg = aa.ModelsPkg
app.PackagePkg = aa.PackagePkg
app.AsAPI = viper.GetBool("api")
app.VCS = viper.GetString("vcs")
app.WithDep = viper.GetBool("with-dep")
Expand Down Expand Up @@ -205,6 +208,14 @@ var newCmd = &cobra.Command{
return errors.WithStack(err)
}

// setup VCS last
if opts.VCS != nil {
// add the VCS generator
if err := run.WithNew(vcs.New(opts.VCS)); err != nil {
return errors.WithStack(err)
}
}

if err := run.Run(); err != nil {
return errors.WithStack(err)
}
Expand Down Expand Up @@ -268,6 +279,7 @@ func init() {
newCmd.Flags().String("docker", "multi", "specify the type of Docker file to generate [none, multi, standard]")
newCmd.Flags().String("ci-provider", "none", "specify the type of ci file you would like buffalo to generate [none, travis, gitlab-ci]")
newCmd.Flags().String("vcs", "git", "specify the Version control system you would like to use [none, git, bzr]")
newCmd.Flags().String("module", "", "specify the root module (package) name. [defaults to 'automatic']")
newCmd.Flags().Int("bootstrap", 4, "specify version for Bootstrap [3, 4]")
viper.BindPFlags(newCmd.Flags())
cfgFile := newCmd.PersistentFlags().String("config", "", "config file (default is $HOME/.buffalo.yaml)")
Expand Down
12 changes: 12 additions & 0 deletions genny/build/_fixtures/coke/actions/a_actions-packr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions genny/newapp/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
pop "github.com/gobuffalo/buffalo-pop/genny/newapp"
"github.com/gobuffalo/buffalo/genny/ci"
"github.com/gobuffalo/buffalo/genny/refresh"
"github.com/gobuffalo/buffalo/genny/vcs"
"github.com/gobuffalo/buffalo/runtime"
"github.com/gobuffalo/genny"
"github.com/gobuffalo/genny/movinglater/dep"
Expand Down Expand Up @@ -128,15 +127,5 @@ func New(opts *Options) (*genny.Group, error) {
gg.Add(g)
}

// setup VCS last
if opts.VCS != nil {
// add the VCS generator
g, err = vcs.New(opts.VCS)
if err != nil {
return gg, errors.WithStack(err)
}
gg.Add(g)
}

return gg, nil
}
16 changes: 4 additions & 12 deletions genny/newapp/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package core

import (
"path/filepath"
"strings"
"testing"

"github.com/gobuffalo/buffalo-docker/genny/docker"
Expand Down Expand Up @@ -38,14 +37,11 @@ func Test_New(t *testing.T) {

res := run.Results()

cmds := []string{"go get github.com/gobuffalo/buffalo-plugins",
cmds := []string{
"go get github.com/gobuffalo/buffalo-plugins",
"go get -t ./...",
}
r.Len(res.Commands, len(cmds))

for i, c := range res.Commands {
r.Equal(cmds[i], strings.Join(c.Args, " "))
}
r.NoError(gentest.CompareCommands(cmds, res.Commands))

expected := commonExpected
for _, e := range expected {
Expand Down Expand Up @@ -102,11 +98,7 @@ func Test_New_Mods(t *testing.T) {
"go get github.com/gobuffalo/buffalo-plugins",
"go mod tidy",
}

for i, c := range res.Commands {
r.Equal(cmds[i], strings.Join(c.Args, " "))
}
r.Len(res.Commands, len(cmds))
r.NoError(gentest.CompareCommands(cmds, res.Commands))

expected := commonExpected
for _, e := range expected {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/gobuffalo/buffalo-pop v1.3.0
github.com/gobuffalo/envy v1.6.11
github.com/gobuffalo/events v1.1.8
github.com/gobuffalo/flect v0.0.0-20181114183036-47375f6d8328
github.com/gobuffalo/flect v0.0.0-20181210151238-24a2b68e0316
github.com/gobuffalo/genny v0.0.0-20181207193730-587570ab2cf7
github.com/gobuffalo/github_flavored_markdown v1.0.7
github.com/gobuffalo/httptest v1.0.6
Expand Down Expand Up @@ -45,7 +45,7 @@ require (
github.com/stretchr/testify v1.2.2
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f
golang.org/x/tools v0.0.0-20181207195948-8634b1ecd393
golang.org/x/tools v0.0.0-20181210150541-e00c0697c2f1
google.golang.org/appengine v1.3.0 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc
)
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ github.com/gobuffalo/flect v0.0.0-20181024204909-8f6be1a8c6c2/go.mod h1:rCiQgmAE
github.com/gobuffalo/flect v0.0.0-20181104133451-1f6e9779237a/go.mod h1:rCiQgmAE4axgBNl3jZWzS5rETRYTGOsrixTRaCPzNdA=
github.com/gobuffalo/flect v0.0.0-20181108195648-8fe1b44cfe32/go.mod h1:rCiQgmAE4axgBNl3jZWzS5rETRYTGOsrixTRaCPzNdA=
github.com/gobuffalo/flect v0.0.0-20181109221320-179d36177b5b/go.mod h1:0HvNbHdfh+WOvDSIASqJOSxTOWSxCCUF++k/Y53v9rI=
github.com/gobuffalo/flect v0.0.0-20181114183036-47375f6d8328 h1:nvA0/snr4wQeCwBYmrbftniJun/kxOjK/Pz3ivb7wis=
github.com/gobuffalo/flect v0.0.0-20181114183036-47375f6d8328/go.mod h1:0HvNbHdfh+WOvDSIASqJOSxTOWSxCCUF++k/Y53v9rI=
github.com/gobuffalo/flect v0.0.0-20181210151238-24a2b68e0316 h1:yXFEtYWu8O6g1GwaSGB7adox0EB7jYSp7F8nqKcpUzw=
github.com/gobuffalo/flect v0.0.0-20181210151238-24a2b68e0316/go.mod h1:en58vff74S9b99Eg42Dr+/9yPu437QjlNsO/hBYPuOk=
github.com/gobuffalo/genny v0.0.0-20180924032338-7af3a40f2252/go.mod h1:tUTQOogrr7tAQnhajMSH6rv1BVev34H2sa1xNHMy94g=
github.com/gobuffalo/genny v0.0.0-20181003150629-3786a0744c5d/go.mod h1:WAd8HmjMVrnkAZbmfgH5dLBUchsZfqzp/WS5sQz+uTM=
github.com/gobuffalo/genny v0.0.0-20181005145118-318a41a134cc/go.mod h1:WAd8HmjMVrnkAZbmfgH5dLBUchsZfqzp/WS5sQz+uTM=
Expand Down Expand Up @@ -513,8 +514,8 @@ golang.org/x/tools v0.0.0-20181203210056-e5f3ab76ea4b/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20181205224935-3576414c54a4/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181206194817-bcd4e47d0288/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181207183836-8bc39b988060/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181207195948-8634b1ecd393 h1:0P8IF6+RwCumULxvjp9EtJryUs46MgLIgeHbCt7NU4Q=
golang.org/x/tools v0.0.0-20181207195948-8634b1ecd393/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181210150541-e00c0697c2f1 h1:DXw7HwufHsO67L7dZ21RNsoFUzQhpHNGN3RvsDAVAH0=
golang.org/x/tools v0.0.0-20181210150541-e00c0697c2f1/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.3.0 h1:FBSsiFRMz3LBeXIomRnVzrQwSDj4ibvcRexLG0LZGQk=
google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
Expand Down
Loading

0 comments on commit 0813411

Please sign in to comment.