github.com/joshdk/godel@v0.0.0-20170529232908-862138a45aee/apps/distgo/cmd/build/cmd.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 build 16 17 import ( 18 "github.com/nmiyake/pkg/dirs" 19 "github.com/palantir/pkg/cli" 20 "github.com/palantir/pkg/cli/cfgcli" 21 "github.com/palantir/pkg/cli/flag" 22 23 "github.com/palantir/godel/apps/distgo/cmd" 24 "github.com/palantir/godel/apps/distgo/config" 25 ) 26 27 const ( 28 parallelFlagName = "parallel" 29 installFlagName = "install" 30 pkgDirFlagName = "pkgdir" 31 ) 32 33 var ( 34 parallelFlag = flag.BoolFlag{ 35 Name: parallelFlagName, 36 Usage: "Build binaries in parallel", 37 Value: true, 38 } 39 installFlag = flag.BoolFlag{ 40 Name: installFlagName, 41 Usage: "Run 'install' before 'build'", 42 Value: true, 43 } 44 pkgDirFlag = flag.BoolFlag{ 45 Name: pkgDirFlagName, 46 Usage: "Use a custom 'pkg' directory for 'install' action (only takes effect if 'install' is true)", 47 } 48 ) 49 50 func DefaultContext() Context { 51 return Context{ 52 Parallel: parallelFlag.Value, 53 Install: installFlag.Value, 54 Pkgdir: pkgDirFlag.Value, 55 } 56 } 57 58 func Command() cli.Command { 59 return cli.Command{ 60 Name: "build", 61 Usage: "Build products", 62 Flags: []flag.Flag{ 63 cmd.ProductsParam, 64 parallelFlag, 65 installFlag, 66 pkgDirFlag, 67 cmd.OSArchFlag, 68 }, 69 Action: func(ctx cli.Context) error { 70 buildCtx := Context{ 71 Parallel: ctx.Bool(parallelFlagName), 72 Install: ctx.Bool(installFlagName), 73 Pkgdir: ctx.Bool(pkgDirFlagName), 74 } 75 76 cfg, err := config.Load(cfgcli.ConfigPath, cfgcli.ConfigJSON) 77 if err != nil { 78 return err 79 } 80 81 wd, err := dirs.GetwdEvalSymLinks() 82 if err != nil { 83 return err 84 } 85 86 osArchs, err := cmd.NewOSArchFilter(ctx.String(cmd.OSArchFlagName)) 87 if err != nil { 88 return err 89 } 90 return Products(ctx.Slice(cmd.ProductsParamName), osArchs, buildCtx, cfg, wd, ctx.App.Stdout) 91 }, 92 } 93 }