github.com/bmoylan/distgo@v1.18.0/cmd/build.go (about)

     1  // Copyright 2016 Palantir Technologies, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package cmd
    16  
    17  import (
    18  	"github.com/spf13/cobra"
    19  
    20  	"github.com/palantir/distgo/distgo"
    21  	"github.com/palantir/distgo/distgo/build"
    22  )
    23  
    24  var (
    25  	buildCmd = &cobra.Command{
    26  		Use:   "build [flags] [product-build-ids]",
    27  		Short: "Build the executables for products",
    28  		RunE: func(cmd *cobra.Command, args []string) error {
    29  			projectInfo, projectParam, err := distgoProjectParamFromFlags()
    30  			if err != nil {
    31  				return err
    32  			}
    33  			return build.Products(projectInfo, projectParam, distgo.ToProductBuildIDs(args), build.Options{
    34  				Parallel: buildParallelFlagVal,
    35  				Install:  buildInstallFlagVal,
    36  				DryRun:   buildDryRunFlagVal,
    37  			}, cmd.OutOrStdout())
    38  		},
    39  	}
    40  )
    41  
    42  var (
    43  	buildParallelFlagVal bool
    44  	buildInstallFlagVal  bool
    45  	buildOSArchsFlagVal  []string
    46  	buildDryRunFlagVal   bool
    47  )
    48  
    49  func init() {
    50  	buildCmd.Flags().BoolVar(&buildParallelFlagVal, "parallel", true, "build binaries in parallel")
    51  	buildCmd.Flags().BoolVar(&buildInstallFlagVal, "install", false, "build products with the '-i' flag")
    52  	buildCmd.Flags().StringSliceVar(&buildOSArchsFlagVal, "os-arch", nil, "if specified, only builds the binaries for the specified GOOS-GOARCH(s)")
    53  	buildCmd.Flags().BoolVar(&buildDryRunFlagVal, "dry-run", false, "print the operations that would be performed")
    54  
    55  	rootCmd.AddCommand(buildCmd)
    56  }