diff options
author | Steve Manuel <nilslice@gmail.com> | 2017-05-22 21:04:27 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-22 21:04:27 -0700 |
commit | 0b7f607b347e46c823774dabf4969758470ae6fd (patch) | |
tree | 9e5d292acba06e4d4b4e4e3009c7a6b7796f6035 /cmd/ponzu/build.go | |
parent | 66c3ad778ccf54566086d535a6ebe4805bf4241f (diff) | |
parent | 7276d308986bfcbd2bbe3d22e2887b622fab52e7 (diff) |
Merge pull request #148 from ponzu-cms/ponzu-dev
[cli] use spf13/cobra for command line interface
Diffstat (limited to 'cmd/ponzu/build.go')
-rw-r--r-- | cmd/ponzu/build.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/cmd/ponzu/build.go b/cmd/ponzu/build.go new file mode 100644 index 0000000..d0f82eb --- /dev/null +++ b/cmd/ponzu/build.go @@ -0,0 +1,58 @@ +package main + +import ( + "path/filepath" + "strings" + + "github.com/spf13/cobra" +) + +func buildPonzuServer() error { + // copy all ./content files to internal vendor directory + src := "content" + dst := filepath.Join("cmd", "ponzu", "vendor", "github.com", "ponzu-cms", "ponzu", "content") + err := emptyDir(dst) + if err != nil { + return err + } + err = copyFilesWarnConflicts(src, dst, []string{"doc.go"}) + if err != nil { + return err + } + + // copy all ./addons files & dirs to internal vendor directory + src = "addons" + dst = filepath.Join("cmd", "ponzu", "vendor") + err = copyFilesWarnConflicts(src, dst, nil) + if err != nil { + return err + } + + // execute go build -o ponzu-cms cmd/ponzu/*.go + cmdPackageName := strings.Join([]string{".", "cmd", "ponzu"}, "/") + buildOptions := []string{"build", "-o", buildOutputName(), cmdPackageName} + return execAndWait(gocmd, buildOptions...) +} + +var buildCmd = &cobra.Command{ + Use: "build [flags]", + Short: "build will build/compile the project to then be run.", + Long: `From within your Ponzu project directory, running build will copy and move +the necessary files from your workspace into the vendored directory, and +will build/compile the project to then be run. + +By providing the 'gocmd' flag, you can specify which Go command to build the +project, if testing a different release of Go. + +Errors will be reported, but successful build commands return nothing.`, + Example: `$ ponzu build +(or) +$ ponzu build --gocmd=go1.8rc1`, + RunE: func(cmd *cobra.Command, args []string) error { + return buildPonzuServer() + }, +} + +func init() { + RegisterCmdlineCommand(buildCmd) +} |