Codebase list golang-github-gobuffalo-packr / a28d1564-de24-492b-8e37-50745921626d/upstream packr / cmd / build.go
a28d1564-de24-492b-8e37-50745921626d/upstream

Tree @a28d1564-de24-492b-8e37-50745921626d/upstream (Download .tar.gz)

build.go @a28d1564-de24-492b-8e37-50745921626d/upstreamraw · history · blame

package cmd

import (
	"context"
	"os"
	"os/exec"

	"github.com/gobuffalo/packr"
	"github.com/gobuffalo/packr/builder"
	"github.com/spf13/cobra"
)

// buildCmd represents the build command
var buildCmd = &cobra.Command{
	Use:                "build",
	Short:              "Wraps the go build command with packr",
	DisableFlagParsing: true,
	RunE: func(cmd *cobra.Command, args []string) error {
		defer builder.Clean(input)
		b := builder.New(context.Background(), input)
		err := b.Run()
		if err != nil {
			return err
		}

		cargs := []string{"build"}
		cargs = append(cargs, args...)
		cp := exec.Command(packr.GoBin(), cargs...)
		cp.Stderr = os.Stderr
		cp.Stdin = os.Stdin
		cp.Stdout = os.Stdout

		return cp.Run()
	},
}

func init() {
	rootCmd.AddCommand(buildCmd)
}