github.com/bmoylan/distgo@v1.18.0/cmd/artifacts.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/artifacts" 22 "github.com/palantir/distgo/distgo/docker" 23 ) 24 25 var ( 26 artifactsCmd = &cobra.Command{ 27 Use: "artifacts", 28 Short: "Print the artifacts for products", 29 } 30 artifactsBuildSubcmd = &cobra.Command{ 31 Use: "build [flags] [product-build-ids]", 32 Short: "Print the paths to the build artifacts for products", 33 RunE: func(cmd *cobra.Command, args []string) error { 34 projectInfo, projectParam, err := distgoProjectParamFromFlags() 35 if err != nil { 36 return err 37 } 38 return artifacts.PrintBuildArtifacts(projectInfo, projectParam, distgo.ToProductBuildIDs(args), artifactsAbsPathFlagVal, artifactsRequiresBuildFlagVal, cmd.OutOrStdout()) 39 }, 40 } 41 artifactsDistSubcmd = &cobra.Command{ 42 Use: "dist [flags] [product-dist-ids]", 43 Short: "Print the paths to the distribution artifacts for products", 44 RunE: func(cmd *cobra.Command, args []string) error { 45 projectInfo, projectParam, err := distgoProjectParamFromFlags() 46 if err != nil { 47 return err 48 } 49 return artifacts.PrintDistArtifacts(projectInfo, projectParam, distgo.ToProductDistIDs(args), artifactsAbsPathFlagVal, cmd.OutOrStdout()) 50 }, 51 } 52 artifactsDockerSubcmd = &cobra.Command{ 53 Use: "docker [flags] [product-docker-ids]", 54 Short: "Print the tags for the Docker images for products", 55 RunE: func(cmd *cobra.Command, args []string) error { 56 projectInfo, projectParam, err := distgoProjectParamFromFlags() 57 if err != nil { 58 return err 59 } 60 if artifactsDockerRepositoryFlagVal != "" { 61 docker.SetDockerRepository(projectParam, artifactsDockerRepositoryFlagVal) 62 } 63 return artifacts.PrintDockerArtifacts(projectInfo, projectParam, distgo.ToProductDockerIDs(args), cmd.OutOrStdout()) 64 }, 65 } 66 ) 67 68 var ( 69 artifactsAbsPathFlagVal bool 70 artifactsRequiresBuildFlagVal bool 71 artifactsDockerRepositoryFlagVal string 72 ) 73 74 func init() { 75 artifactsBuildSubcmd.Flags().BoolVar(&artifactsAbsPathFlagVal, "absolute", false, "print the absolute path for artifacts") 76 artifactsBuildSubcmd.Flags().BoolVar(&artifactsRequiresBuildFlagVal, "requires-build", false, "only prints the artifacts that require building (omits artifacts that are already built and are up-to-date)") 77 artifactsCmd.AddCommand(artifactsBuildSubcmd) 78 79 artifactsDistSubcmd.Flags().BoolVar(&artifactsAbsPathFlagVal, "absolute", false, "print the absolute path for artifacts") 80 artifactsCmd.AddCommand(artifactsDistSubcmd) 81 82 artifactsDockerSubcmd.Flags().StringVar(&artifactsDockerRepositoryFlagVal, "repository", "", "specifies the value that should be used for the Docker repository (overrides any value(s) specified in configuration)") 83 artifactsCmd.AddCommand(artifactsDockerSubcmd) 84 85 rootCmd.AddCommand(artifactsCmd) 86 }