github.com/bmoylan/distgo@v1.18.0/cmd/dist.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  	"time"
    19  
    20  	"github.com/spf13/cobra"
    21  
    22  	"github.com/palantir/distgo/distgo"
    23  	"github.com/palantir/distgo/distgo/dist"
    24  )
    25  
    26  var (
    27  	distCmd = &cobra.Command{
    28  		Use:   "dist [flags] [product-dist-ids]",
    29  		Short: "Create distributions for products",
    30  		RunE: func(cmd *cobra.Command, args []string) error {
    31  			projectInfo, projectParam, err := distgoProjectParamFromFlags()
    32  			if err != nil {
    33  				return err
    34  			}
    35  
    36  			var configFileModTime *time.Time
    37  			if !distForceFlagVal {
    38  				// if force flag is false, use modification time of configuration file
    39  				configFileModTime = distgoConfigModTime()
    40  			}
    41  			return dist.Products(projectInfo, projectParam, configFileModTime, distgo.ToProductDistIDs(args), distDryRunFlagVal, cmd.OutOrStdout())
    42  		},
    43  	}
    44  )
    45  
    46  var (
    47  	distDryRunFlagVal bool
    48  	distForceFlagVal  bool
    49  )
    50  
    51  func init() {
    52  	distCmd.Flags().BoolVar(&distDryRunFlagVal, "dry-run", false, "print the operations that would be performed")
    53  	distCmd.Flags().BoolVar(&distForceFlagVal, "force", false, "create distribution outputs even if they are considered up-to-date")
    54  
    55  	rootCmd.AddCommand(distCmd)
    56  }