Repository: gobuffalo/buffalo
Pull request #1599 (2019-02-20 14:58:44)

adds buffalo install alias for buffalo build


Patch:
diff --git a/buffalo/cmd/build.go b/buffalo/cmd/build.go
index 10d0c18e..645e2388 100644
--- a/buffalo/cmd/build.go
+++ b/buffalo/cmd/build.go
@@ -34,7 +34,7 @@ var buildOptions = struct {
 
 var xbuildCmd = &cobra.Command{
 	Use:     "build",
-	Aliases: []string{"b", "bill"},
+	Aliases: []string{"b", "bill", "install"},
 	Short:   "Build the application binary, including bundling of assets (packr & webpack)",
 	RunE: func(cmd *cobra.Command, args []string) error {
 		ctx, cancel := sigtx.WithCancel(context.Background(), os.Interrupt)
diff --git a/genny/build/bin.go b/genny/build/bin.go
index 8737aaaa..f056374d 100644
--- a/genny/build/bin.go
+++ b/genny/build/bin.go
@@ -10,7 +10,10 @@ import (
 )
 
 func buildCmd(opts *Options) (*exec.Cmd, error) {
-	buildArgs := []string{"build"}
+	if len(opts.GoCommand) == 0 {
+		opts.GoCommand = "build"
+	}
+	buildArgs := []string{opts.GoCommand}
 
 	if !gomods.On() {
 		buildArgs = append(buildArgs, "-i")
@@ -26,16 +29,19 @@ func buildCmd(opts *Options) (*exec.Cmd, error) {
 	if len(tf) > 0 {
 		buildArgs = append(buildArgs, "-tags", tf.String())
 	}
-	bin := opts.App.Bin
-	if runtime.GOOS == "windows" {
-		if !strings.HasSuffix(bin, ".exe") {
-			bin += ".exe"
+
+	if opts.GoCommand == "build" {
+		bin := opts.App.Bin
+		if runtime.GOOS == "windows" {
+			if !strings.HasSuffix(bin, ".exe") {
+				bin += ".exe"
+			}
+			bin = strings.Replace(bin, "/", "\\", -1)
+		} else {
+			bin = strings.TrimSuffix(bin, ".exe")
 		}
-		bin = strings.Replace(bin, "/", "\\", -1)
-	} else {
-		bin = strings.TrimSuffix(bin, ".exe")
+		buildArgs = append(buildArgs, "-o", bin)
 	}
-	buildArgs = append(buildArgs, "-o", bin)
 
 	flags := []string{}
 
diff --git a/genny/build/options.go b/genny/build/options.go
index ece82808..3b5edc28 100644
--- a/genny/build/options.go
+++ b/genny/build/options.go
@@ -39,8 +39,10 @@ type Options struct {
 	// Empty by default
 	TemplateValidators []TemplateValidator `json:"-"`
 	// Mod is the -mod flag
-	Mod      string `json:"mod"`
-	rollback *sync.Map
+	Mod string `json:"mod"`
+	// GoCommand is the `go X` command to be used. Default is "build".
+	GoCommand string `json:"go_command"`
+	rollback  *sync.Map
 }
 
 // Validate that options are usuable
@@ -61,5 +63,8 @@ func (opts *Options) Validate() error {
 	if opts.rollback == nil {
 		opts.rollback = &sync.Map{}
 	}
+	if len(opts.GoCommand) == 0 {
+		opts.GoCommand = "build"
+	}
 	return nil
 }


Test patch:
diff --git a/genny/build/bin_test.go b/genny/build/bin_test.go
index d54984e2..230d5ee7 100644
--- a/genny/build/bin_test.go
+++ b/genny/build/bin_test.go
@@ -26,7 +26,8 @@ func Test_buildCmd(t *testing.T) {
 	}
 
 	opts := &Options{
-		App: meta.New("."),
+		App:       meta.New("."),
+		GoCommand: "build",
 	}
 	c, err := buildCmd(opts)
 	r.NoError(err)
@@ -82,7 +83,8 @@ func Test_buildCmd_Unix_RemovesExe(t *testing.T) {
 	app := meta.New(".")
 	app.Bin = "bin/build.exe"
 	opts := &Options{
-		App: app,
+		App:       app,
+		GoCommand: "build",
 	}
 	c, err := buildCmd(opts)
 	r.NoError(err)
@@ -112,3 +114,60 @@ func Test_buildCmd_Windows_AddsExe(t *testing.T) {
 		eq("go build -o bin\\build.exe", c)
 	}
 }
+
+func Test_installCmd(t *testing.T) {
+	envy.Set("GO_BIN", "go")
+	gomods.Force(true)
+	r := require.New(t)
+
+	eq := func(s string, c *exec.Cmd) {
+		if runtime.GOOS == "windows" {
+			s = strings.Replace(s, "bin/build", `bin\build.exe`, 1)
+			s = strings.Replace(s, "bin/foo", `bin\foo.exe`, 1)
+		}
+		r.Equal(s, strings.Join(c.Args, " "))
+	}
+
+	opts := &Options{
+		App:       meta.New("."),
+		GoCommand: "install",
+	}
+	c, err := buildCmd(opts)
+	r.NoError(err)
+	eq("go install", c)
+
+	opts.Environment = "bar"
+	c, err = buildCmd(opts)
+	r.NoError(err)
+	eq("go install -tags bar", c)
+
+	opts.App.Bin = "bin/foo"
+	c, err = buildCmd(opts)
+	r.NoError(err)
+	eq("go install -tags bar", c)
+
+	opts.WithSQLite = true
+	c, err = buildCmd(opts)
+	r.NoError(err)
+	eq("go install -tags bar sqlite", c)
+
+	opts.LDFlags = "-X foo.Bar=baz"
+	c, err = buildCmd(opts)
+	r.NoError(err)
+	eq("go install -tags bar sqlite -ldflags -X foo.Bar=baz", c)
+
+	opts.Static = true
+	c, err = buildCmd(opts)
+	r.NoError(err)
+	eq("go install -tags bar sqlite -ldflags -linkmode external -extldflags \"-static\" -X foo.Bar=baz", c)
+
+	opts.LDFlags = "-X main.BuildTime=asdf"
+	c, err = buildCmd(opts)
+	r.NoError(err)
+	eq("go install -tags bar sqlite -ldflags -linkmode external -extldflags \"-static\" -X main.BuildTime=asdf", c)
+
+	opts.LDFlags = "-X main.BuildVersion=asdf"
+	c, err = buildCmd(opts)
+	r.NoError(err)
+	eq("go install -tags bar sqlite -ldflags -linkmode external -extldflags \"-static\" -X main.BuildVersion=asdf", c)
+}